导出:
const formElement = document.createElement('form');
formElement.style.display = 'display:none;';
formElement.method = 'post';
formElement.action = window.configUrl.serverUrl + url;
formElement.target = '_self';
const exportQueryData = [
{ name: 'departmentCode','' : },
{ name: 'idCard', value: '' },
{ name: 'name', value: '' },
{ name: 'policeCard', value: '' },
{ name: 'roleId', value: '' },
{ name: 'state', value: '' },
];
queryData.forEach((item) => {
const inputElement = document.createElement('input');
inputElement.type = 'hidden';
inputElement.name = item.name;
inputElement.value = item.value;
formElement.appendChild(inputElement);
})
document.body.appendChild(formElement);
formElement.submit();
document.body.removeChild(formElement);
导入:
const formData = new FormData();
formData.append('file', info.file);
axios({
url:"url",
method:"post",
data:{
...参数
},
})
.then((res)=>{
if (res) {
if (res.type && res.type === 'application/octet-stream') { // 内容错误返回错误文件
message.error('您上传的文件存在数据异常,请查看下载文件,修复后再次上传');
const a = document.createElement('a');
a.download = `${异常文档}.xls`;
a.href = URL.createObjectURL(res);
a.click();
} else if (res.status && res.status === 'success') {
message.success('导入成功!');
} else if (res.status && res.status === 'error') {
message.error('您导入的文件存在格式错误,请上传模板文件!');
}
}
})标签:const,name,inputElement,res,前端,导出,value,formElement,导入 From: https://www.cnblogs.com/evenbest/p/18034769