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

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

作者: Pluto_7a23 | 来源:发表于2021-07-30 17:32 被阅读0次
     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();
    });
    
    

    相关文章

      网友评论

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

          本文链接:https://www.haomeiwen.com/subject/xwdcvltx.html