在这里插入代码片// 点击下载
download = () => {
const { table_Data } = this.props
const blob = new Blob([JSON.stringify(table_Data)], {type: 'text/plain'}) // {type : 'application/json'}
let a = document.createElement('a')
let url = URL.createObjectURL(blob)
a.href = url
a.download = '表格数据'
a.click()
setTimeout(() => {
//删除创建的URL
window.URL.revokeObjectURL(url)
}, 0)
}
// 相关链接
// 【官方链接】 https://developer.mozilla.org/zh-CN/docs/Web/API/Blob
// 【HTML5】Blob对象 https://www.jianshu.com/p/e45522c7f6c9
// URL.createObjectURL和URL.revokeObjectURL https://www.jianshu.com/p/2fb76868248b
axios.post(api.url, param, {responseType: 'blob'})
.then(res => {
console.log(res, '请求')
let url = URL.createObjectURL(res.data)
let a = document.createElement('a')
a.setAttribute('download', '1.pdf')
a.href = url
a.click()
})
Blob 下载
最新推荐文章于 2024-09-04 10:44:39 发布