I am trying to query a quote API for a freeCodeCamp project I'm updating to React.js. I am now trying to use Fetch
or Axios
to query the API but it's caching the response in the browser. I know in $ajax
there is a { cache: false }
that would force the browser to do a new request.
Is there some way I will be able to do the same with Fetch
or Axios
?
The cache-control
setting seems to be already set to max-age: 0
by Axios
.
This is my code I have that is querying the 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.`)
})
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…