关于文件导出vue+iview

Posted on 2020-09-08 15:14  凡凡0410  阅读(229)  评论(0编辑  收藏  举报
 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'
  })
}

 

Copyright © 2024 凡凡0410
Powered by .NET 9.0 on Kubernetes