vue下载二进制流图片

1、应项目要求,后台返回二进制流,而且乱码

2、红色为必须

this.$axios.post('/fishweb/agent/downLoad',this.stringify({filename:'qrCode.jpg'}), {
        responseType: 'arraybuffer' //指定返回数据的格式为blob
      }).then((res) => {
        var src='data:image/jpg;base64,'+ btoa(new Uint8Array(res).reduce((data, byte) => data + String.fromCharCode(byte), ''));
        this.srcImg = src; //图片回显
        var link = document.createElement('a');
        link.href = src;
        link.download = "qrCode.jpg";
        link.click();
      })

猜你喜欢

转载自blog.csdn.net/lilongwei4321/article/details/82803513