赞
踩
1
第一种 调用
window.open
methods:{
getDown() {
window.open(baseUrl+ "/report/data_excel?curDay=" +this.date + "&token=" +localStorage.getItem("token") );
},
}
2
第二种 使用axios 动态创建a标签 使用a标签的href属性 a.click() a.remove() js代码 excelMonse() { const a = document.createElement('a') axios({ responseType: 'blob', //必须的 method: "get", url: "/member/account_list" }).then(res => { // // 切割出文件名 // const fileNameEncode = res.headers['content-disposition'].split('filename=')[1] // 解码 // const fileName = decodeURIComponent(fileNameEncode) console.log(res.headers); const blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; application/octet-stream' }) const fileUrl = window.URL.createObjectURL(blob) a.href = fileUrl console.log('url', fileUrl) a.setAttribute('download', 'fileName') //固定的文件名称 //a.setAttribute('download', fileName)//动态文件名称 a.style.display = 'none' a.click() a.remove() }) },
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。