<el-upload
:auto-upload="false"
:on-success="success_file"
:on-change="changeFile"
:on-error="onerror"
:headers="headers"
:with-credentials="true"
:show-file-list="false"
:limit="1"
ref="upload"
:action="`${url}/baseParam/courseTypeParam/importCourseTypes`"
accept='.xls,.xlsx'
>
<el-tooltip class="item" effect="dark" content="批量导入课程分类" placement="top">
<div class="img"></div>
</el-tooltip>
</el-upload>
computed: {
headers() {
return {
'Authorization': this.tokenId ,
}
},
}
//还有一种需求是 不立刻上传需要二次确认之后 :auto-upload="false"主要是这个属性
changeFile(file){
if(file.status=='ready'){
this.$confirm(`上传将覆盖所以分类?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
// this.headers = {
// Authorization: this.tokenId
// }
console.log(this.$refs.upload)
this.$refs.upload.submit();
})
.catch(() => {
this.$message({
type: 'info',
message: '已取消'
});
this.$refs.upload.clearFiles();
});
}
},
vue el-upload 上传设置请求头 二次确认
最新推荐文章于 2024-10-16 11:24:40 发布
这篇博客介绍了如何使用Element UI的上传组件实现批量导入课程分类功能。通过设置`auto-upload=false`来阻止自动上传,添加二次确认对话框确保用户在覆盖现有分类前进行确认。在用户点击确定后,利用`$refs.upload.submit()`提交文件。同时,内容涉及到上传文件的格式限制(`.xls, .xlsx`),以及自定义请求头和错误处理。
3389

被折叠的 条评论
为什么被折叠?



