vue 将图片流转换为 base64 的图片 src

    getVerify() {
      let that = this;
      axios({
        method: "GET",
        url: `http://192.168.7.61:3000/base/BaseApiService/createCaptchaCode?access_token=bjcenter`,
        responseType: "arraybuffer", //这个在请求头里必须加
      })
        .then((res) => {
          return (
            "data:image/png;base64," +
            btoa(
              new Uint8Array(res.data).reduce(
                (data, byte) => data + String.fromCharCode(byte),
                ""
              )
            )
          );
        })
        .then((res) => {
          that.verify = res;
          console.log("res", res);
        })
        .catch((e) => {
          console.log(e);
        });
    },

  

posted @ 2022-06-24 15:35  1点  阅读(1744)  评论(0编辑  收藏  举报