export function downLoad (res, name, type) { // 封装方法 let resfileName = decodeURI(res.headers['content-disposition'].split('=')[1]) // 取后台命名 let fileName = '' if (resfileName && resfileName !== 'null' && resfileName !== '' && resfileName.length) { fileName = resfileName } else { // 后端未命名处理 fileName = (name || '-') + parseTime(new Date(), '{y}-{m}-{d}') + '.xls' } if (type) { fileName = name } const blob = new Blob([res.data], {}) if ('download' in document.createElement('a')) { // 非IE下载 const elink = document.createElement('a') elink.download = fileName elink.style.display = 'none' elink.href = URL.createObjectURL(blob) document.body.appendChild(elink) elink.click() URL.revokeObjectURL(elink.href) document.body.removeChild(elink) } else { // IE10+下载 navigator.msSaveBlob(blob, fileName) } }
handleExport (obj) { // 导出接口调用 return request({ url: '/api/export', method: 'get', params: obj, responseType: 'blob' // 重点! }) }
标签:文件,resfileName,document,elink,导出,fileName,blob,&&,js From: https://www.cnblogs.com/everseventh/p/18364144