解決方法:
// 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 }