我正在try 查询一个freeCodeCamp项目的quote API,我正在更新以做出react .js.我现在try 使用Fetch
或Axios
来查询API,但它正在浏览器中缓存响应.我知道在$ajax
中有一个{ cache: false }
会迫使浏览器执行新的请求.
有没有办法让我用Fetch
或Axios
也能做到这一点?
cache-control
设置似乎已经被Axios
设置为max-age: 0
.
这是我查询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.`)
})
}