需求: 一个可以下载的接口,前端做出导出功能 接口: https://www.cnblogs.com/kaibindirver/p/15470706.html
方法一:
axios请求参数要加上 参考: https://www.cnblogs.com/kaibindirver/p/15396789.html
responseType: 'arraybuffer'
调用时加上红色的代码
async down2(){ let { response } = await rzCheck02(`fortime=${this.time1}&query=${this.selctaction}&totime=${this.time2}&index=2`); const objectUrl = window.URL.createObjectURL(new Blob([response], {type: "application/vnd.ms-excel"})); const a = document.createElement('a'); a.href = objectUrl; a.download = '2023.xls'; a.click(); a.remove(); },
方法二:
用open可行,单交互是会再起一个标签页下载
async down(){
// window的方法可行
window.open(`/v2/tool/check?fortime=${this.time1}&query=${this.selctaction}&totime=${this.time2}&index=2&type=${this.type}&page=4000`)
},