vue 后端返回图片乱码处理方法

 

new_posters() {
      axios
        .get("接口地址", { responseType: "arraybuffer" }) //设置请求头
        .then(data => {
          console.log(data);
          //自定义名字 imgUrl 将请求回来的图片信息放到里面
          this.imgUrl =
            "data:image/png;base64," +
            btoa(
              new Uint8Array(data.data).reduce(
                (data, byte) => data + String.fromCharCode(byte),
                ""
              )
            );
        })
        .catch(err => {});
    }

显示图片

<img alt="图片加载失败..." :src="imgUrl" />

 

Supongo que te gusta

Origin blog.csdn.net/m0_55551893/article/details/121423059
Recomendado
Clasificación