vue FormData上传文件并下载
后端需要配合测试上传文件返回,就临时写了一个上传文件和下载
<input type="file" @change="onChange($event)">
onChange(event){
console.log(event)
const params = new FormData();
params.append('file', event.target.files[0]);
console.log(params.get('file'));
axios({
url: '/app/excel/orderConsignment',
method: 'post',
data: params,
headers: {'Content-Type': 'multipart/form-data'},
responseType: 'blob'
}).then(res=> {
const blor = new Blob([res.data],{type:'application/octet-stream'});
const bloburl = URL.createObjectURL(blor);
let link = document.createElement("a");
link.href = bloburl;
link.text = "下载";
link.setAttribute('download', 'excel.xlsx')
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(bloburl);
}).catch(err=> {
console.log(err)
})
},