element el-upload-文件上传时覆盖上一个文件

<div style="text-align: center">
          <el-upload
            ref="upload"
            class="upload-demo"
            drag
            action="/"
            accept=".xlsx"
            :limit="2"
            :auto-upload='false'
            :file-list="fileList"
            :before-upload="beforeUpload"
            :http-request="handleUploadCrow"
            :on-remove="handleRemove"
            :on-change="onChange"       
          >
            <i class="el-icon-upload" />
            <div class="el-upload__text">
              将文件拖到此处,或<em>点击上传</em>
            </div>
            <div slot="tip" class="el-upload__tip">
              1.仅支持导入xls/xlsx格式的文件
            </div>
            <div slot="tip" class="el-upload__tip">
              2.导入文件后需要和系统做匹配,找出已注册会员,这部分会员将作为您的优惠券投放人群
            </div>
          </el-upload>
          <div style="margin-top: 18px">
            <el-button type="primary" @click="uploadFile">确 定</el-button>
            <el-button @click="dialogImportVisible = false">取 消</el-button>
          </div>
        </div>

limit设置上传限制2个,然后判断onchang的fileList长度实现替换


>

/**
     * 上传文件前验证格式
     */ beforeUpload(file) {
      console.log(file)
      const typeArr = [
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        'application/vnd.ms-excel',
      ]
      if (typeArr.indexOf(file.type) === -1) {
        this.$message.error('请上传格式为 .xls或.xlsx 的文件')
        return false
      }
    },
    /**
     * 上传确定
     */
    handleUploadCrow(event) {
      console.log(event)
      adjustImpor({ file: event.file,type:this.formData.type })
        .then((res) => {
          console.log(res)
          this.formData.pointAdjustList = res.data.pointAdjustList
          this.formData.pointSum = res.data.pointNumSum
          this.formData.customerSum = res.data.customerSum
          this.custNum = res.data.success
        })
        .catch((err) => {
          console.log(err)
        })
    },
    /**
     * 移除文件
     */
    handleRemove() {
      this.$set(this.fileList, this.fileList, '')
    },
    /**
     * 确定上传
     */ uploadFile() {
      this.$refs.upload.submit()
      this.dialogImportVisible = false
    },
    /**
     * 文件覆盖
     */
    onChange(file, fileList) {
      console.log(file,fileList)
      if (fileList.length > 1) {
         fileList.splice(0, 1);
      }
    },


  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值