问题
业务需求中要在上传前加入一个弹出框用于客户确认。
由于之前做过各种文件大小判断等,我兴致冲冲的使用了 before-upload,逻辑和平时使用都觉得只要我在弹出框中return false 或 return true 就可以达成我的目的,但是很遗憾,before-upload 直接执行 false 或 true,根本不会等异步执行完再执行。
解决方式(使用手动上传)
将默认的自动上传关闭 :auto-upload="false"
<el-upload :action="this.baseURL + '/***" method="post" :data="{}"
:on-progress='uploadBefore' :on-success='uploadSuccess' :auto-upload="false" :show-file-list="false"
ref="upload11" :on-change='beforeUpload' accept=".xls,.xlsx" enctype="multipart/form-data">
导入
</el-upload>
使用 on-change 添加弹出框功能
beforeUpload(file) {
//判断 status 为上传初始化
if(file.status=='ready'){
this.$confirm("确认导入数据吗?", "提示", {}).then(() => {
//调用对象 upload11 的提交方法
this.$refs.upload11.submit();
}).catch(() => {
//调用对象 upload11 的清空已上传的文件列表方法
this.$refs.upload11.clearFiles();
});
}
},