vue2 axios请求从后台获取文件流(自定义导出excel)
import axios from 'axios'export default {post(url, param, title) {axios.post(url, param, { responseType: 'arraybuffer' }).then((res) => {if(res.status == "200") {...
·
import axios from 'axios'
export default {
post(url, param, title) {
axios.post(url, param, { responseType: 'arraybuffer' })
.then((res) => {
if(res.status == "200") {
const aLink = document.createElement("a");
let blob = new Blob([res.data], {type: "application/vnd.ms-excel"})
aLink.href = URL.createObjectURL(blob)
aLink.download = title
aLink.click()
document.body.appendChild(aLink)
}
})
}
}
(注意:此情况,后台返回的数据是以文件流的形式返回的)
更多推荐
已为社区贡献3条内容
所有评论(0)