X0r*_*r0N 5 android caching react-native expo
我正在尝试为我正在创建的演示应用程序使用随机图像生成器。
我已经尝试了端点:
但是当我将图像列表添加到我的页面时:
<View>
<Image
source={{ uri: 'http://thecatapi.com/api/images/get?format=src&type=gif&size=small' }}
style={{ width: 100, height: 100 }}
/>
<Image
source={{ uri: 'http://thecatapi.com/api/images/get?format=src&type=gif&size=small' }}
style={{ width: 100, height: 100 }}
/>
<Image
source={{ uri: 'http://thecatapi.com/api/images/get?format=src&type=gif&size=small' }}
style={{ width: 100, height: 100 }}
/>
</View>
Run Code Online (Sandbox Code Playgroud)
期望是对于每个Image组件,将显示不同的图像。奇怪的是,这不适用于 Android。似乎图像或 url 被缓存在某处,因此当使用相同的 URI 再次呈现图像时,将显示相同的图像。
我在 IOS 上尝试过相同的应用程序(该应用程序是使用 react native expo.io 创建的)。IOS 上的图像与预期不同,这似乎是 Android 特有的问题。
有没有办法防止android缓存图像并在每次Image渲染组件时显示不同的图像?
在 2020 年,它仍然是 React Native 的一个问题(正如 Dishant Walia 提到的)。现在来自 github 的最佳解决方案是:
在 url 后添加查询字符串,适用于两个平台
<Image
style={styles.drawerAccountImg}
source={uri: this.state.photoURL + '?' + new Date()}
/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3370 次 |
| 最近记录: |