React Native iOS正在保存提取的数据,直到我卸载应用程序?

问题描述 投票:0回答:1

我想弄清楚导致这个问题的原因。当我打开应用程序时,我会转到第一个屏幕。该屏幕包含从json数据中获取的数据。然后,当我切换到另一个屏幕并返回到第一个屏幕时,仍然存在相同的数据。我会解释为什么它应该是不同的。我使用随机查询(RAND())从mysql数据库中获取数据。每次回到第一个屏幕时它应该是不同的。

当我卸载并重新安装应用程序时,我会看到新获取的数据,但如果我重复这些步骤,问题仍然存在。

这适用于Android,但不适用于iOS:

componentDidUpdate(prevProps, prevState) {
  if (!prevState.user_image) {

    fetch('https://www.exmaple.com/React/user.php')
     .then((response) => response.json())
     .then((responseJson) => {
       this.setState({
         isLoading: false,
         user_image:  responseJson

         }, function() {
           const {userLikes, user_image} =  this.state;
           this.setState({
               combinedArray: userLikes.map(likes => Object.assign(likes, user_image.find(images => images.id == likes.id)))
           });


       });
     })
     .catch((error) => {
       //console.error(error);
     });

  }
}

我不知道Xcode是否有某种获取数据缓存。基本上发生的事情是(在Web开发术语中)CSS缓存,但是使用获取的数据。如果这是有道理的。

此外,我正在使用react-native-react-navigation选项卡导航...也许这是问题,它正在保存提取的数据?

ios xcode reactjs react-native
1个回答
0
投票

事实证明我是对的!这是因为获取是缓存。我不得不在fetch中插入任何缓存标头。

© www.soinside.com 2019 - 2024. All rights reserved.