<el-upload
style="display:inline-flex;padding: 0px 10px;"
class="upload-demo"
action=""
:on-change="handleChange"
:on-exceed="handleExceed"
:on-remove="handleRemove"
:file-list="fileListUpload"
:limit="limitUpload"
accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
:auto-upload="false">
<el-button>导入</el-button>
</el-upload>
//导入数据
handleChange(file, fileList){
data.fileTemp = file.raw
if(data.fileTemp){
if((data.fileTemp.type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') || (data.fileTemp.type == 'application/vnd.ms-excel')){
data.importfxx(data.fileTemp)
} else {
this.$message({
type:'warning',
message:'附件格式错误,请删除后重新上传!'
})
}
} else {
this.$message({
type:'warning',
message:'请上传附件!'
})
}
},
importfxx(obj) {
let params=obj
let formData = new FormData();
//把文件信息放入对象中
var blob = new Blob([obj], { type: obj.type},{filename:obj.name});
formData.append("file", blob);
proxy.$Api.Post(`请求`,formData).then((res)=>{
if(res.code===1&&res.data===0){
proxy.$message.success({
type:'success',
message: '导入成功!',
})
data.queryKeyGroups()
}else {
proxy.$message.error({
type:'error',
message: '您有'+res.data+'条数据未导入成功!',
})
}
})
},
handleRemove(file,fileList){
this.fileTemp = null
},
导入的时候主要注意:我在与后台进行联调的时候,后台要的formData 表单数据。所以要把file放到formData