【问题标题】:React Native Fetch API returning old dataReact Native Fetch API 返回旧数据
【发布时间】:2018-11-12 04:54:06
【问题描述】:

我的 fetch API 总是返回旧的 json 数据。我的应用程序为我的用户列表请求 API,它在开始时工作,但是当我发布新用户并刷新我的列表(调用相同的 fetch 函数)时,它返回了相同的列表(没有新用户)。但只要我完全关闭我的应用程序并重新打开它,它就会起作用。我想知道为什么会发生这种情况。我需要“重置”我的 fetch API 函数吗?有这样的功能吗?

这是我的获取函数:

fetch(GET_USER_SESSION, {
  method: 'GET',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
  }
})
.then((response) => response.json())
.then((data) => {
  return data // return same old list
}).catch((err) => this.showError('Error Signing Up, Please Try Again.'));

有什么想法吗?非常感谢!

【问题讨论】:

  • 你找到解决办法了吗?

标签: android react-native fetch-api


【解决方案1】:

在 fetch API 中将其添加到您的标头中:'Cache-Control': 'no-cache'

【讨论】:

    猜你喜欢
    • 2021-11-04
    • 2019-08-03
    • 2016-08-30
    • 1970-01-01
    • 1970-01-01
    • 2019-07-03
    • 2018-03-01
    • 1970-01-01
    • 2018-03-14
    相关资源
    最近更新 更多