javascript - ReactJs 函数调用,而是看到一个表达式 no-unused-expressions
问题描述
我正在尝试在 reactjs 准备一个 restfulpi。但是因为我是reactjs新手,英文也不是很流利,所以遇到了一个问题。我的应用程序的目的是列出出版商的书籍。您可以从下面访问我的代码和错误。如果你帮助我,我可以做到。谢谢你。
错误:
第 21 行:期望一个赋值或函数调用,而是看到一个表达式 no-unused-expressions
我的代码:
`` `
class App extends Component {
state = {
books:[]
}
componentWillMount(){
axios.get('http://localhost:3000/books').then(( response)=>{
this.setState({
books: response.data
})
});
}``
`` `
render() {
let books = this.state.books.map((book) =>
{
return
(
<tr key={book.id}>
<td>{book.id}</td>
<td>{book.title}</td>
<td>{book.rating}</td>
<td>
<Button color="success" size="sm" className="mr-2">Edit </Button>
<Button color="danger" size="sm">Sil</Button>
</td>
</tr>
)
});``
`` `
return (
<div className="App container">
<h1>Book List</h1><br></br>
<Table>
<thead>
<tr>
<th>#</th>
<th>Title</th>
<th>Rating</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{books}
</tbody>
</Table>
</div>
);``
解决方案
您的方法中缺少该return
语句render
。
render() {
....
...
return (
<tbody>
{books}
</tbody>
)
}
推荐阅读
- excel - 删除列中大于数字的单元格
- android-espresso - 如何使用 BySelector Text 在 espresso 中忽略大小写来查找元素
- java - 当我使用 FileInputStream 导出 JAR 文件时出现 FileNotFoundException
- fortran - 无法在派生类型中打印可分配的分配状态
- jhipster - 使用 jhipster 生成的角度导航栏无法正常工作
- amazon-ec2 - 在 ec2 完成在其上运行的进程之前停止 ec2 以缩小规模
- algorithm - 背包问题 - 从 5 组中选择最佳可能的项目组合,包括每组 1 项
- spotfire - 在spotfire中链接两个表
- google-cloud-platform - 谷歌云平台服务帐号无法访问项目
- javascript - JS 分数数组:如何在分数数组中添加一个数字并剔除较小的数字?