React Native WebView关闭缓存

网上搜索没有找到关闭React Native下webview控件的缓存的方法,经测试找到解决方案,记录如下

  • 核心思路:通过请求时设置请求头,使页面缓存过期

关键代码

<View style={styles.container}>
    <WebView source={{ uri: "http://somehost/somepath/file.html", method: 'GET', headers: { 'Cache-Control':'no-cache'} }} window').width, height: Dimensions.get('window').height }}></WebView>
</View>
  • 核心代码: 在source里面指定headers中的Cache-Control为no-cache