Element-ui中Upload组件上传前弹窗询问

单于煌
2023-12-01

①设置Upload组件为隐藏,设置弹窗为隐藏,页面上显示Button

②点击按钮触发弹窗,给弹窗中的按钮绑定触发上传事件

③在上传事件中调用upload组件中的handleClick()方法 

 

​
//弹窗
<el-dialog
    title="提示"
    :visible.sync="showCover"
    width="30%"
    :show-close="false">
        <span>导入指令是否覆盖?</span>
        <span slot="footer" class="dialog-footer">
            <el-button @click="cancelUpload">取 消</el-button>
            <el-button type="primary" @click="commitUpload">确 定</el-button>
        </span>
</el-dialog>

//文件上传
<el-upload
      ref="upload"
      style="display: none"
      class="upload-demo"
      action="/你/自/己/的/接/口"
      :on-success="updateList"
      :on-error="uploadError"
      :before-upload="beforeListUpload"
      multiple
      :limit="3"
    >
</el-upload>

​
triggerUpload() {
    this.showCover = true;
},
cancelUpload() {
    this.showCover = false;
},
commitUpload() {
    this.$refs['upload'].$refs['upload-inner'].handleClick()
    this.showCover = false;
}

 类似资料: