uni-app 图片转base64

urlBase64(url) {
  var toBase64Url;
  uni.request({
    url: url,
    method: 'GET',
    responseType: 'arraybuffer',
    success: async res => {
      let base64 = wx.arrayBufferToBase64(res.data); //把arraybuffer转成base64
      toBase64Url = 'data:image/jpeg;base64,' + base64; //不加上这串字符,在页面无法显示
      console.log(toBase64Url);
    }
  });
}

let coverImg:'https://xxxx/xxx.jpg' 
this.urlTobase64(coverImg);

 

posted @ 2020-05-25 16:47  ___mouM  阅读(5789)  评论(0编辑  收藏  举报