【问题标题】:Fetch caching response - no-cache headers not working as expected获取缓存响应 - 无缓存标头未按预期工作
【发布时间】:2017-12-29 05:52:15
【问题描述】:

我一直在为 freecodecamp 做random quote machine 项目,但我似乎无法停止缓存 api 的响应。

我尝试了各种答案:

我以为我曾经有过它:

fetch(this.url, {cache: 'no-cache'})
    .then(res => res.json())

...但我只是在开发者工具中禁用了缓存。

请帮忙。 :-D。

这是我一直试图让它发挥作用的地方: https://codepen.io/JonathanDWood/pen/gRNNKx

【问题讨论】:

    标签: javascript ajax vue.js cache-control fetch-api


    【解决方案1】:

    我已经设法通过将Date.now() 附加到网址来修复它。我真的不喜欢它作为一个永久的解决方案,因为它不能解决底层缓存问题,但它可以工作。

    fetch(this.url+ Date.now(), {cache: 'no-store'})
        .then(res => res.json())
    

    【讨论】:

      猜你喜欢
      • 2018-06-05
      • 2020-10-20
      • 1970-01-01
      • 2016-05-02
      • 2013-08-20
      • 1970-01-01
      • 1970-01-01
      • 2011-05-17
      • 1970-01-01
      相关资源
      最近更新 更多