下面使用的是若依框架中的axios请求
api:通用
import request from '@/utils/request' export function guideCome(data){ return request( { url: '/sys/client/export', method: 'post', responseType: 'blob', data } ) }
当前页面:
const fileName = this.$route.query.name + '这里是修改需要的文件类型'
// 导出 guideCome () { guideCome({ intentionSign: this.displaySwitching }).then(res => { const blob = new Blob([res]) const fileName = this.$route.query.name + '.xls' const dlink = document.createElement('a') if ('download' in document.createElement('a')) { // 非IE下载 const dlink = document.createElement('a') dlink.download = fileName dlink.style.display = 'none' dlink.href = URL.createObjectURL(blob) document.body.appendChild(dlink) dlink.click() URL.revokeObjectURL(dlink.href) // 释放URL 对象 document.body.removeChild(dlink) } else { // IE10+下载 navigator.msSaveBlob(blob, fileName) } }) },
标签:文件,document,const,接口,fileName,dlink,blob,guideCome,解析 From: https://www.cnblogs.com/0722tian/p/17360052.html