一.做界面
this.$route.query.id是上个页面传的参数
domain.testUrl是本地端口
二、写方法
fileDownload(path) {
console.log(path);
this.$http
.get( path,
{ responseType: “arraybuffer” },//告诉服务器你期望的响应格式
{ headers: { “content-type”: “application/json;charset=ISO8859-1” } }
)
.then((res) => {
// this.export_show = false;
console.log(res.data);
// let name = res.headers[‘content-disposition’].substring(20);
const blob = new Blob([res.data]); //new Blob([res])中不加data就会返回下图中[objece objece]内容(少取一层)
console.log(blob);
const fileName = “物流方案.xls”; //下载文件名称
const elink = document.createElement(“a”);//在页面中创建一个a标签
console.log(elink);
elink.download = fileName;
elink.style.display = “none”;
elink.href = URL.createObjectURL(blob)//用createObjectURL这个方法创建一个url赋值给href
document.body.appendChild(elink);
elink.click();
URL.revokeObjectURL(elink.href); // 释放URL 对象
document.body.removeChild(elink);
});
private filedown(row: any) {
let params: any = {
waveNumber: row.waveNumber,
}
Service.getFile(params).then(({ data }) => {
console.log(data)
let blob = new Blob([data], {
type: ‘application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;’,
})
let link = document.createElement(‘a’)
link.href = URL.createObjectURL(blob)
link.style.display = ‘none’
document.body.appendChild(link)
link.download = ‘账单列表.xlsx’
link.click()
document.body.removeChild(link)
})
}