setExcelLogFn: async function(){ let this_ = this; var obj={ dt_json:JSON.stringify({ advance:[] }), time_range:JSON.stringify(this.time_range) }; let info = await sendExcel(obj);
//关键代码 const blob = new Blob([info.data], { type: 'application/octet-stream' }); let fileName = this.formBase.title+'.xls'; 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) // 释放URL 对象 document.body.removeChild(elink) } else { // IE10+下载 navigator.msSaveBlob(blob, fileName) }; },
export const sendExcel = async (data) => { return await request({ url:'/xxx/xxx/xxxx', //向后台请求的地址 method: 'post', data: data, responseType: 'arraybuffer' }) }