//接口需要在headers中设置编码方式,才能识别formData文件
export function BranchConfigUpload(params) {
return request({
headers: { 'Content-Type': 'multipart/form-data' },
method: 'post',
url: '',
data: params.data
})
}
// 选择文件限制
handleExceed(files, fileList) {
this.$message.warning(`当前限制选择 1 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`)
},
// 上传
submitConfigImport() {
if (!this.fileList) {
this.$message.warning('请先选取文件!')
return false
}
const params = new FormData()
params.append('uploadFile', this.fileList.raw)
this.loading1 = true
BranchConfigUpload({
data: params
}).then((res) => {
if (res.code === '0') {
this.loading1 = false
this.getTable()
this.$message({
showClose: true,
duration: 2000,
message: '导入成功',
type: 'success',
offset: 300
})
}
}, () => {
this.$message({
showClose: true,
duration: 2000,
message: '导入失败',
type: 'error',
offset: 300
})
this.loading1 = false
})
},
// 文件改变
fileChange(val) {
// console.log(val);
this.fileList = val
this.progressFlag = 0
},
// 文件列表移除
handleRemove(file, fileList) {
this.fileList = null
},
JS上传表单(包含上传文件)
最新推荐文章于 2024-08-11 18:40:36 发布