我正在尝试为我要更新到 React.js 的 freeCodeCamp 项目查询报价 API。我现在正在尝试使用Fetch或Axios查询 API,但它正在浏览器中缓存响应。我知道$ajax有一个{ cache: false }会强制浏览器执行新请求。
有什么方法可以让我用Fetch或做同样的事情Axios吗?
该cache-control设置似乎已设置为max-age: 0by Axios。
这是我查询 API 的代码。
generateQuote = () => {
axios.get('https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1')
.then(response => {
const { title, content, link } = response.data[0];
console.log(title, content, link)
this.setState(() => ({ title, content, link }));
})
.catch(err => {
console.log(`${err} whilst contacting the quote API.`)
})
}
