1. 程式人生 > >axios get post下載文件

axios get post下載文件

parse ech The cli app nav move splay err


let url = URLParser.submitUrl(`/download`);
return new Promise((resolve, reject) => {
axios({
method: ‘get‘,// post
url: url,
     data : ‘‘,
responseType: ‘blob‘
}).then((response) => {
const blob = new Blob([response.data]);
let fileName = ‘notification-request.xsd‘;
if (‘download‘ in document.createElement(‘a‘)) { // 非IE下載
const elink = document.createElement(‘a‘);
elink.download = fileName;
elink.style.display = ‘none‘;
elink.href = URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
URL.revokeObjectURL(elink.href);// 釋放URL 對象
document.body.removeChild(elink)
} else { // IE10+下載
navigator.msSaveBlob(blob, fileName)
}
resolve(response);
}).catch((err) => {
reject(err)
})
})

axios get post下載文件