第一種方法:需要設定響應類型,這裡還需要安裝 npm install js-file-download --save ,然後引用 var fileDownload = require('js-file-download'),使用詳情見github;
Vue.axios.post(url_post,params_post,{responseType: 'arraybuffer'}).then((res) => {
let fileName = res.headers['content-disposition'].match(/fushun(\S*)xls/)[0];
fileDownload(res.data,fileName);
}).catch((res) => {
// 錯誤資訊
})
第二種方法:需要設定響應類型,并用到Blob類型,
了解BlobVue.axios.post(url_post,params_post,{responseType: 'arraybuffer'}).then((res) => {
let blob = new Blob([res.data], {type: "application/vnd.ms-excel"});
let objectUrl = URL.createObjectURL(blob);
window.location.href = objectUrl;
}).catch((res) => {
// 錯誤資訊
})
每一次的記錄,都是向前邁進的一步