可能我们在使用element-ui 的upload上传组件的时候不希望在选择完文件后就马上上传,而是希望在点击提交后再统一上传,其实element-ui也是支持的。首先设置auto-upload="false",然后在通过refs手动触发提交操作。
\n\n\n\n<el-upload
\n\n\n\nref="importRef"
\n\n\n\nname="filename"
\n\n\n\n:data="{template: userImportModule}"
\n\n\n\n:action="baseUrl + '/erm-index-service/roleUser/importUsers'"
\n\n\n\n:headers="headers"
\n\n\n\n:show-file-list="true"
\n\n\n\n:on-success="updateFileSuccess"
\n\n\n\n:on-error="updateFileError"
\n\n\n\n:file-list="currFileList"
\n\n\n\n:limit="1"
\n\n\n\n:auto-upload="false">
\n\n\n\n<el-button type="primary" plain>选择文件</el-button>
\n\n\n\n</el-upload>
\n\n\n\n手动触发:this.$refs.importRef.submit()
\n\n\n\n提交前判断是否有选择文件:
\n\n\n\nif (!this.$refs.importRef.uploadFiles.length) {
\n\n\n\nthis.$message.warning("请选择文件")
\n\n\n\nreturn false
\n\n\n\n}
\n\n\n\n如果想实现一次只能上传一个文件,并且后一个文件会默认覆盖前一个文件的话,可以将limit =1 去掉,通过on-change事件触发,截取最后一个文件赋值给upload组件
\n\n\n\nthis.$refs.importRef.uploadFiles = this.$refs.importRef.uploadFiles.slice(-1)
\n