<Button @click="getLoadTemplate" type="primary">下载模板</Button>
export const getTemplate = () => {
return axios.request({
url: "...",
method: "get",
responseType: "blob" //**********************************
})
}
getTemplate () {
getTemplate().then(res => {
// res.data 是一个file流文件
const blob = new Blob([res.data], { type: 'application/vnd.ms-excel' })
//const blob = new Blob([res.data],{type:'application/octet-stream'})
//const blob = new Blob([res.data], "application/vnd.ms-excel;charset=utf-8")
const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(blob)
downloadElement.href = href
downloadElement.download = '模板.xls'
document.body.appendChild(downloadElement)
downloadElement.click()
document.body.removeChild(downloadElement)
window.URL.revokeObjectURL(href)
}).catch(err => {
console.log(err)
})
},