Vue学习之—— 文件上传,IE 10 以下及谷歌低版本不支持 document.getElementById("file").files[0]的问题

Vue 文件上传,IE 10 以下及谷歌低版本不支持 document.getElementById("file").files[0],文件获取不到的解决方法,

可以采用element ui 的Upload组件,参考代码如下:

<el-form id="importFileForm" label-width="140px" size="small">
<el-form-item label="选择导入的文件:">
        <el-upload 
class="upload-demo" 
style="position:absolute;width:100px"
            action="https://jsonplaceholder.typicode.com/posts/"
            :before-upload="beforeupload"
            multiple
            :limit="1"
            :http-request="httprequest"
            accept=".xlsx,.xls">
            <el-button icon="el-icon-upload2">上传附件</el-button>
         </el-upload>
         <span style="margin-left:120px">{{importFileName}}</span>
      </el-form-item>
      <el-form-item >
           <el-button @click="submit()">提交</el-button>
       </el-form-item>
 </el-form>
export default {
    name: "FlowImport",
    data() {
        return {
            importFile:null,
            importFileName:null,
            param:new FormData(),//表单要提交的参数
        };
    },
    methods: {
        beforeupload(file){
            this.importFileName = file.name;
            this.param.append("file", file, file.name);
            return false;
        },
        //覆盖默认的上传行为
        httprequest() {

        },
        submit(){
            if(this.param.get("file") === undefined || this.param.get("file") === null){
                this.$message({
                    message: "请上传文件!",
                    type: 'warning'
                });
                return false;
            }
            //提交到后台
            uploadIFile(this.param).then((res) => {
                
            }
); 
        },
    }
};
<style>
    #importFile .el-upload__input{
        display: none;
    }
</style>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值