【发布时间】:2022-01-01 15:39:59
【问题描述】:
handleNext = async () => {
console.log("Next");
let url =
'https://newsapi.org/v2/top-headlines?country=in&apiKey=eae0696c32814d94af8f1f9c908cb49d?&page=${this.state.page + 1}';
let data = await fetch(url);
let parsedData = await data.json();
this.setState({
page: this.state.page + 1,
articles: parsedData.articles,
});
};
当我尝试使用 ${this.state.page + 1} 时出现错误:Unexpected template string expression no-template-curly-in-string and the url did not get the value of this prop
【问题讨论】:
-
看看rule details,您应该会找到答案。 (您应该在字符串周围使用反引号(
`),而不是引号('))