vue 处理后端返回的文档流

xiazai(){
      this.$_api.kanbanApi
      .Get({
        responseType: 'blob',
        url: 'KanbanItemData/exportExcel' //`${this.selectComponents.config.dataUrl}/exportExcel`
      }).then(res=>{
        console.log(res,'下载模板');
      }).catch(err=>{
        console.log(err,'err'); //响应封装问题  正常应该在then中
         const url = window.URL.createObjectURL(new Blob([err],{type:"application/vnd.ms-excel;charset=utf-8"}));
            const link = document.createElement('a');
            link.href = url;
            let fileName = '下载'+".xlsx";
            link.setAttribute('download', fileName);
            document.body.appendChild(link);
            link.click();
      })
    },

  

posted @ 2023-03-13 15:24  沁猿春  阅读(185)  评论(0编辑  收藏  举报