vue 上传组件 选择文件之前有校验 ,校验通过弹出文件选择框,否则不弹

<el-upload
        ref="upload"
        :on-remove="handleRemove"
        :http-request="handlePreview"
        :before-remove="beforeRemove"
        :limit="1"
        :file-list="fileListUpload"
        :auto-upload="false"
        :on-success="uploadSuccess"
        :on-error="uplodError"
        class="upload-insurant"
        action=""
      >
        <el-button
          v-show="show"
          ref="importbtn"
          slot="trigger"
          size="small"
          type="primary"
        >选取文件</el-button>

        <el-button
          style="margin-left: 10px;"
          size="small"
          type="primary"
          @click="beforeAvatarUpload()"
          :disabled="isDisabled"
        >选取文件</el-button>

        <el-button
          :disabled="isDisabled"
          style="margin-left: 10px;"
          size="small"
          type="primary"
          @click="submitUpload"
        >
          上传
        </el-button>
      </el-upload>

el-upload 中第一个按钮默认为上传按钮(就是点击后可以弹出文件框)
首先:
1、 首先定义一个隐藏的按钮,该按钮为上传按钮,(第一个)
2、 在定义一个普通按钮 第二个按钮 和第一个可以一样,(第二个)
然后:
隐藏按钮 要添加 ref=“importbtn” (第一个)
第二个按钮要写一个点击事件 @click=“beforeAvatarUpload()”。(第二个)

原理就是通过点击第二个按钮来添加判断、校验等一系列操作,通过后 this. r e f s . i m p o r t b t n . refs.importbtn. refs.importbtn.el.click()
触发隐藏按钮点击事件(第一个按钮)

beforeAvatarUpload() {
if (!this.multipleSelection1.length) {
return this.KaTeX parse error: Expected 'EOF', got '}' at position 81: …ext: '确定' }) }̲ else { this.refs.importbtn.$el.click() //很重要
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值