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



我试图找出导致此问题的原因。当我打开应用程序时,我转到第一个屏幕。屏幕包含从 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选项卡导航...也许这就是问题所在,它正在保存获取的数据?

事实证明我是对的!这是因为提取正在缓存。我必须在提取中插入任何缓存标头。

最新更新