vue 后端直接返回文件流 如何进行操作

2021-07-30  本文已影响0人  Pluto_7a23
 const binaryData = [];
 binaryData.push(res.data);//后端返回的值 
  let url = window.URL.createObjectURL(new Blob(binaryData, {type: 'application/vnd.ms-excel'}));//二进制转换
  window.open(url)  //跳转浏览器打开或者下载或者赋值到img
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
this.$http({method:'post',url:'连接',responseType: 'arraybuffer',参数}).then((res) => {
    const binaryData = [];
    binaryData.push(res.data);
    let url = window.URL.createObjectURL(new Blob(binaryData ,{type: 'application/zip'}));//二进制转换
    var anchor = document.createElement("a");
    anchor.href = url;
    anchor.download = decodeURI('车辆信息.zip');
    anchor.click();
});

上一篇下一篇

猜你喜欢

热点阅读