js下载文件方法记录
downLoadExcel() {
this.downloading = true
axios.get(/xxxx
, { responseType: ‘blob’, params: { token: xxxx } }).then(res => {
if (res.status == ‘200’) {
const blob = new Blob([res.data], { type: ‘application/vnd.openxmlformats- officedocument.spreadsheetml.sheet;charset=utf-8’ })
let url = window.URL.createObjectURL(blob);
let link = document.createElement(“a”);
link.style.display = “none”;
link.setAttribute(“download”, “xxx”);
link.href = url;
document.body.appendChild(link);
link.click();
link.remove()
this.downloading = false
}
})
},