使用element-ui中的el-upload組件時攜帶其他參數

<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'
      })
    }
  }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章