请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

Image.prefetch如何使用

视频中说prefetch是预加载,提前把图片下载下来存到本地磁盘,问题是下次怎么直接从磁盘读取,是直接使用相同的url然后react内部自己自动读取本地对应的图片吗?就像下面这样

<Image source={{uri: imageUri}} />

正在回答 回答被采纳积分+3

插入代码

1回答

FE大公爵 2023-04-12 11:05:35
是的,prefetch就是先加载到本地缓存,下次可以读取缓存,加载速度会快一点
0 回复 有任何疑惑可以回复我~
  • prefetch 是不是安卓兼容的不好    
     Image.prefetch(imageUrl)
          .then(data => {
            console.log('prefetch success', data);
            const source = Image.resolveAssetSource({uri: imageUrl});
            console.log(`source Uri: ${source.uri}`);
            if (source && source.uri.startsWith('file://')) {
              setImageSrc(source.uri);
              console.log('Image is cached');
            } else {
              console.log('Image is not cached');
            }
          })
          .catch(e => {
            console.log('prefetch error', e); 
          });
    我一直打印  Image is not cached
    回复 有任何疑惑可以回复我~ 2023-07-11 17:42:12
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号