vue上传excel文件

<el-Button @click="dialogVisible = true">批量导入数据</el-Button>

 <el-dialog title="批量导入数据" :visible.sync="dialogVisible" width="30%" :before-close="handleClose" append-to-body>
      <el-row>
        <div class="el-form-item__content">
          <el-upload ref="upload" accept=".xls,.xlsx" action="#" :auto-upload="false" :multiple="false"
            :file-list="fileList" :before-upload="beforeUpload" :http-request="uploadHttpRequest"
            :on-remove="fileRemove" :on-change="fileChange">
            <el-button size="small" type="primary">选择文件</el-button>
            <div slot="tip" class="el-upload__tip">一次只能上传一个xls/xlsx文件,且不超过10M</div>
          </el-upload>
        </div>
      </el-row>
      <el-row>
        <el-button size="small" @click="closeDialog">取 消</el-button>
        <el-button type="primary" size="small" @click="submitUpload">上 传</el-button>
      </el-row>
    </el-dialog>

data() {
    return {
      dialogVisible: false, //批量导入数据弹框
      uploadLoading: '',
      fileList: [],
      }
  }
  
handleClose(done) {
      this.dialogVisible = false;
    },
  
    beforeUpload(file) {
   
      const isType = file.type === 'application/vnd.ms-excel'
      const isTypeComputer = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
      const fileType = isType || isTypeComputer
      if (!fileType) {
        this.$message.error('上传文件只能是xls/xlsx格式!')
      }


      const fileLimit = file.size / 1024 / 1024 < 10;
      if (!fileLimit) {
        this.$message.error('上传文件大小不超过10M!');
      }
      return fileType && fileLimit
    },

    uploadHttpRequest(param) {
      const formData = new FormData()append('key', value)
      formData.append('fileName', param.file) 
      formData.append('storeId', this.storeId)
      getgoodsExcil(formData).then(res => {
       if(res.code=='200' && res.message=="success"){
             this.$Message.success("批量上传成功");
             this.dialogVisible=false;
             param.onSuccess();
             this.init();
             this.fileList=[];
       }else{
         this.dialogVisible=false;
         this.$Message.success(this.success);
          param.onError();
          this.init();
          this.fileList=[];
       }
      })
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值