1、首先使用uni.getImageInfo获取图片信息,src就是图片路径。
uni.getImageInfo({
src: item.newsImg,
success: res => {
console.log(res , 'res ')
},
fail: err => {
console.log(err, 'err')
}
})
2、之后使用了大佬的插件(image-tools - DCloud 插件市场)
在成功的uni.getImageInfo的成功的回调中使用pathToBase64(res.path).then(),res.path就是返回的图片的本地路径。
pathToBase64(res.path).then(base64 => {
newsPath: base64
uni.setStorageSync('NEWS',newsPath)
}).catch(error => {
console.error(error)
})