const that = this;
request({
url: ‘XXXXX‘,
method: ‘GET‘,
responseType: ‘arraybuffer‘,
success: function(res) {
const base64 = wx.arrayBufferToBase64(res);
that.setData({
userImageBase64: `data:image/jpg;base64,${base64}`
});
}
});
wxml展示图片
<image src=‘{{userImageBase64}}‘ style=‘width: 100rpx; height: 100rpx;‘ />
wx.chooseImage({
success (res) {
// tempFilePath可以作为img标签的src属性显示图片
const tempFilePaths = res.tempFilePaths;
const fileManager = wx.getFileSystemManager();
const base64 = fileManager.readFileSync(tempFilePaths[0], ‘base64‘);
console.log(‘=============================‘, base64);
},
fail () {
wx.showToast({
title: ‘获取图片失败‘,
icon: ‘success‘,
duration: 2000
})
}
})
原文:https://www.cnblogs.com/itxing/p/15175595.html