需要在封装接口的地方加入:
responseType: 'blob', //重要!
下图是具体业务处理方法:
exportPl({
storeId: this.$route.params.id
}).then(res => {
let fileName = res.headers['content-disposition'].split('=')[1]
// 获取文件名
let objectUrl = URL.createObjectURL(new Blob([res.data]))
// 文件地址
const link = document.createElement('a')
link.download = fileName
link.href = objectUrl
link.click()
}).catch(e => {
})