1.引入axios =》 import axios from axios;
2.某个需要触发的事件;
3.事件触发 发送请求:this.axios({
method: 'get',
responseType: 'blob', //改变响应类型
url: url
}).then(data => {
let url = window.URL.createObjectURL(new Blob([data])) // new Blob([data])用来创建URL的file对象或者blob对象
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttrbute('download', '保存的文件的名称')
document.body.appendChild(link)
link.click()
})
后序: emmmm,这个我的第一篇博客,如果有什么不足之处请大家多多指教,我也希望在这里能够和大家一起相互成长哈哈哈哈哈哈