所以我用Visual Studio代码构建了整个项目,我在Chrome和Explorer上测试了它,它工作了,它只需按下一个按钮就可以检索一个新的引用和一个作者,太棒了,我想是时候把它放到codepen中了,不,不起作用。这是发生了什么,我使用http://quotesondesign.com/api-v4-0/来获取我的报价,当你把这个放到浏览器中,你会看到它检索http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1的问题似乎是,如果你输入这个,你会得到一个报价,但是,如果你输入相同的链接(注意,不刷新页面,但使用相同的链接),你会得到相同的报价,在铬,但是,它会给你一个新的报价,所以,所以,我试着看看,如果我使用的代码依赖铬,但它根本不工作,因为在铬的代码依赖的应用程序接口调用将不会检索任何数据。这是我现在正在使用的一个函数。我用于获取新函数的代码如下所示。
getRandomQuote = event =>{
fetch('https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1')
.then(response => response.json())
.then(data => {
if(data[0].content && data[0].title && data[0].link){
let {quote} = this.state;
let quoteData=data[0];
quote.content = quoteData.content;
quote.link = quoteData.link;
quote.title = quoteData.title;
this.setState({
quote,
isLoaded:true
})
}
else{
return console.error('No Quote :(')
}
})
}
这是我的代码的链接:https://codepen.io/russiandobby/pen/OqaxWW?editors=1111,我如何让它检索新的cote?
发布于 2019-03-22 04:09:46
好了,现在我觉得自己很愚蠢,经过一些研究,我发现我所要做的就是把我的请求从
fetch('https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1')
至
fetch('https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1', {cache: "reload"})
在我这样做之后,它开始在所有浏览器上工作,并检索新的引用,我已经禁止m有2个小时,所有只需要不到1行就可以修复itT_T
https://stackoverflow.com/questions/55288388
复制相似问题