const base64 = this.data.imgBase // base64码
const time = new Date().getTime();
const imgPath = wx.env.USER_DATA_PATH + "/poster" + time + "share" + ".png";
//如果图片字符串不含要清空的前缀,可以不执行下行代码.
const imageData = base64.replace(/^data:image\/\w+;base64,/, "");
const fs = wx.getFileSystemManager();
fs.writeFileSync(imgPath, imageData, "base64");
fs.close()
this.data.imgUrls.push(imgPath)
wx.previewImage({
urls:this.data.imgUrls,
current: imgPath,
success: (res => {
console.log(res);
}),
fail: (err => {
console.log(err);
})
})
this.setData({
imgUrls:[]
})
微信小程序base64图片转为本地临时路径
于 2023-04-26 14:11:45 首次发布