vue下载后端文件流

接口加上:

responseType: "arraybuffer",
export function postExport(data) {
    return request({
        url: 'http。。。',
        method: 'POST',
        responseType: "arraybuffer",//加上这行
        data
    })
}

页面里面:

 let url = window.URL.createObjectURL(
                  new Blob(['文件流'], {
                    type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8",
                  })
                );
              let link = document.createElement("a");
              link.style.display = "none";
              link.href = url;
              link.setAttribute("download", "比价文件");
              document.body.appendChild(link);
              link.click();
              document.body.removeChild(link); //下载完成移除元素
              window.URL.revokeObjectURL(url); //释放掉blob对象

 

posted @ 2022-11-03 18:54  肥晨  阅读(165)  评论(0编辑  收藏  举报