首页 > 其他分享 >vue下载后端文件流

vue下载后端文件流

时间:2022-11-03 19:14:27浏览次数:50  
标签:body 文件 vue url window link document 下载

接口加上:

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对象

 

标签:body,文件,vue,url,window,link,document,下载
From: https://www.cnblogs.com/naitang/p/16855521.html

相关文章