後端返回的數據在network的preview中,是一堆碼。
download () {
axios({
method: 'get',
url: baseUrl, //baseUrl是後端給你的下載的接口地址
//看後臺規定的類型,responseType屬性根據你的實際情況確定
responseType: 'arraybuffer'
}).then(res => {
//假設返回的數據在res中!!!
const data = res
const url = window.URL.createObjectURL(new Blob([data]),
// 要轉化的類型,我這個是xslx文件
{ type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })
const link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', '院系專業信息Excel格式示例.xlsx')
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
})
},