<el-upload
action="/api/oss/file/add"
:headers="headers" // 如果頭部需要傳token
multiple
:limit="1" // 限制文件個數
:before-upload="handleBefore"
:on-success="handleSuccess"
:data="pdfData"
accept=".pdf" // 限制文件格式>
<el-button size="small" type="primary">上傳PDF</el-button>
</el-upload>
pdfData: {
'參數1': '',
'參數2': '',
'參數3': ''
},
headers: {
Authorization: Cookies.get('token')
//從cookie裏獲取token,並賦值 Authorization ,而不是token
}
// 上傳前的回調函數
handleBefore(file) {
const _vm = this;
_vm.pdfData.參數1 = '值1';
_vm.pdfData.參數2 = '值2';
_vm.pdfData.參數3 = '值3';
}
// 上傳成功回調
handleSuccess(res) {
const _vm = this;
if (res.status == 200) {
_vm.$message({
message: 'Success!',
type: 'success'
})
} else {
_vm.$message({
message: 'Upload Error!',
type: 'error'
})
}
}