vue 导出数据的实现
btnExport() {console.log('导出')/**** @params* exportEnum导出种类,*/// let params = {//exportEnum: val// }let con...
·
btnExport() {
console.log('导出')
/**
*
* @params
* exportEnum 导出种类,
*/
// let params = {
// exportEnum: val
// }
let config = {
responseType: 'blob'
}
// 根据你的内容是否填加入参params
this.$axios
.get(MAINURL + '/materialRrewindRecord/downloadRecordExcel', config)
.then(res => {
console.log(res)
// console.log(window.decodeURI(res.headers['content-disposition'].split('=')[1], 'UTF-8'))
const url = window.URL.createObjectURL(
new Blob([res.data], {
type: 'application/vnd.ms-excel,charset=utf-8'
})
)
const link = document.createElement('a')
// window.decodeURI(res.headers['content-disposition'].split('=')[1], 'UTF-8')
const fileName = 'window.decodeURI(res.headers['content-disposition'].split('=')[1], 'UTF-8')'
link.style.display = 'none'
link.href = url
link.setAttribute('download', fileName)
//注意:上面的self.$route.query.type是你要下载的文件名加文件后缀,例如test.docx
document.body.appendChild(link)
link.click()
URL.revokeObjectURL(link.href) // 释放URL对象
document.body.removeChild(link)
this.promptTitle = '导出成功'
this.promptStatus = true
this.isPrompt = true
this.clearDsq()
})
.catch(err => {
console.log(err)
})
},
更多推荐
已为社区贡献11条内容
所有评论(0)