vue中img标签显示二进制流

2020-11-03  本文已影响0人  剑圣_盖小聂

管理系统中,头像图片后台返回的是二进制流,

后台返回结果

处理:

getUserPhoto().then((response) => {

      let bytes = new Uint8Array(response);

      let storeData = "";

      let len = bytes.byteLength;

      for (let i = 0; i < len; i++) {

        storeData += String.fromCharCode(bytes[i]);

      }

      this.imageUrl = "data:image/png;base64," + window.btoa(storeData);

    });

代码
上一篇下一篇

猜你喜欢

热点阅读