vue el-upload 上传设置请求头 二次确认

这篇博客介绍了如何使用Element UI的上传组件实现批量导入课程分类功能。通过设置`auto-upload=false`来阻止自动上传,添加二次确认对话框确保用户在覆盖现有分类前进行确认。在用户点击确定后,利用`$refs.upload.submit()`提交文件。同时,内容涉及到上传文件的格式限制(`.xls, .xlsx`),以及自定义请求头和错误处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<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();
            });
          }
        },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

前端代码の搬运工

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值