HTML部分
class="file-uploader" multiple
:custom-request="(data) => onFileUpload(data, 'cjtj')">
上传文件
JS部分
onFileUpload ({ file, name }, type) { // 文件上传
this.loading[type] = true
const formData = new FormData()
formData.append('file', file, name)
formData.append('type', type)
const instance = this.$http.create({ withCredentials: true })
instance.post(this.config.apis.fileUpload, formData, {
headers: {
'x-csrftoken': localStorage.getItem('TOKEN')
}
}).then(resp => {
const { code, msg } = resp.data
if (code != 200) {
this.$message.error(`上传失败.${msg}`)
}
}).finally(() => {
this.loading[type] = false
})
}