当前位置:   article > 正文

uniapp将网络图片转为base64格式存在缓存中_uni.getimageinfo base64

uni.getimageinfo base64

1、首先使用uni.getImageInfo获取图片信息,src就是图片路径。

  1. uni.getImageInfo({
  2. src: item.newsImg,
  3. success: res => {
  4. console.log(res , 'res ')
  5. },
  6. fail: err => {
  7. console.log(err, 'err')
  8. }
  9. })

2、之后使用了大佬的插件(image-tools - DCloud 插件市场

        在成功的uni.getImageInfo的成功的回调中使用pathToBase64(res.path).then(),res.path就是返回的图片的本地路径。

  1. pathToBase64(res.path).then(base64 => {
  2. newsPath: base64
  3. uni.setStorageSync('NEWS',newsPath)
  4. }).catch(error => {
  5. console.error(error)
  6. })

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/木道寻08/article/detail/885121
推荐阅读
相关标签
  

闽ICP备14008679号