vue 从后台获取文件流 导出excel
<template><div class="container" ref="loadElement"></div></template>import axios from 'axios'export default {post(url, param, title) {axios.post(url...
·
<template>
<div class="container" ref="loadElement">
</div>
</template>
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.setAttribute('download', '客户资源' + '.xlsx') // 设置下载文件名称
aLink.click()
//document.body.appendChild(aLink)
this.$refs.loadElement.appendChild(aLink)
}
})
}
}
更多推荐
已为社区贡献5条内容
所有评论(0)