【发布时间】:2020-02-06 05:19:54
【问题描述】:
- 当我输入 1sport1 时,我看到了结果。
- 当我输入 1sport12 时,我没有看到任何结果。
- 所以我需要显示没有找到数据的类型。
- 在清除所有内容时,它应该清除文本框。
- 但问题是这一行
console.log("resp.json()--->", resp.json().[[PromiseValue]]); - 我想当长度为 0 时,我会显示找不到数据。
- 但我收到此错误。
/src/searchbar.js: Unexpected token (31:48) - 我正在评论以下行,以便您可以在浏览器中看到输出
// console.log("resp.json()--->", resp.json().[[PromiseValue]]); // display: this.state.noData ? "" : "none" - 您能告诉我在没有来自 api 的数据时如何显示未找到数据吗?
- 在下面提供我的代码 sn-p 和沙箱。
https://codesandbox.io/s/jovial-cdn-14o1w
getQuery = async (type = "", search_tag = "") => {
var url = "https://hn.algolia.com/api/v1/search?tags=";
const resp = await fetch(`${url}${type}&query=${search_tag}`);
// console.log("resp.json()--->", resp.json().[[PromiseValue]]);
return resp.json();
};
render() {
console.log("this.state.noData--->", this.state.noData);
return (
<div>
<input type="text" onChange={this.searchByKeyword} />
<p
style={
{
// display: this.state.noData ? "" : "none"
}
}
>
No data found
<p>clear all</p>
</p>
{/* <Scroll /> */}
</div>
);
【问题讨论】:
标签: javascript html css reactjs redux