import axios from 'axios'
let filename = xxx
axios({
url: '/api/xxx/',
method: 'post',
responseType: 'blob',
params: {
xxx: xxxx
...
}
}).then(res => {
let blob = new Blob([res.data])
if ('download' in document.createElement('a')) {
let link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
link.download = filename
link.click()
window.URL.revokeObjectURL(link.href)
} else {
navigator.msSaveBlob(blob, filename)
}
}).catch(error => {
console.log('error: ', error)
})
vue 下載文件
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.