前端怎么写导出

55 阅读1分钟

首先就是api 封装 export function financialExport(params) { // 返回一个axios对象 => promise // 返回了一个promise对象 return request({ url: /xxxx/xxxx/${params}, method: "GET", header: { headers: { 'Content-Type': 'application/x-download' } }, responseType: 'blob' }); }

然后调用具体写
try { const response = await financialExport( ?username=${userName}&company_name=${this.company_name} ); const blob = new Blob([response], { type: "application/vnd.ms-excel", }); const url = URL.createObjectURL(blob); const link = document.createElement("a"); link.href = url; link.download = "filename.xlsx"; document.body.appendChild(link); link.click(); document.body.removeChild(link); URL.revokeObjectURL(url); this.excelselect = ""; this.excledialogVisible = false; } catch (error) { console.log(error); }