使用element-ui中的el-upload组件时携带其余参数

解决方法:
// templateapi

 1 <el-upload
 2   action="/api/oss/file/add"
 3   :headers="headers" // 若是头部须要传token
 4   multiple
 5   :limit="1" // 限制文件个数
 6   :before-upload="handleBefore"
 7   :on-success="handleSuccess"
 8   :data="pdfData"
 9   accept=".pdf" // 限制文件格式>
10   <el-button size="small" type="primary">上传PDF</el-button>
11 </el-upload>

 


// js:cookie

 1   pdfData: {
 2     '参数1': '',
 3     '参数2': '',
 4     '参数3': ''
 5   },
 6   headers: {
 7     Authorization: Cookies.get('token') 
 8     //从cookie里获取token,并赋值 Authorization ,而不是token
 9   }
10 // 上传前的回调函数
11   handleBefore(file) {
12     const _vm = this;
13     _vm.pdfData.参数1 = '值1';    
14     _vm.pdfData.参数2 = '值2';    
15     _vm.pdfData.参数3 = '值3';    
16   }
17 // 上传成功回调
18   handleSuccess(res) {
19     const _vm = this;
20     if (res.status == 200) {
21       _vm.$message({
22         message: 'Success!',
23         type: 'success'
24       })
25     } else {
26       _vm.$message({
27         message: 'Upload Error!',
28         type: 'error'
29       })
30     }
31   }
相关文章
相关标签/搜索