使用官方的uni.getFileSystemManager().writeFile()方法可将base64码转成的二维码显示在画布上,代码如下:
const obj = {
page: 'pages/sort/goodsDetail',
co_Nu: this.goodInfo.co_Nu
}
const _this = this
cenerateQrCode(obj).then(res => {
if (res.success) {
// 图片路径
var codeimg = wx.env.USER_DATA_PATH + '/ewm.jpg';
uni.getFileSystemManager().writeFile({
filePath:codeimg, // 图片路径
data: res.data, // 返回的base64
encoding: 'base64',
success() {
_this.posterData.codeImg.url = codeimg //最终地址
}
})
}
})
如果单纯想base64转图片显示在页面可执行以下代码:
const imgUrl = 'data:image/jpg;base64,' + res.data
最终效果如下:
需要生成海报组件的友友们可参照以下地址: