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

解决方法:
// template

 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:

 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   }

 

 

posted @ 2019-11-08 10:34  zaijinyang  阅读(11894)  评论(0编辑  收藏  举报