如何解决Uncaught TypeError:this.state.books.map不是函数错误

时间:2019-06-03 06:41:14

标签: dictionary

如何解决Uncaught TypeError:this.state.books.map不是函数

const List =(props) =>(
<tr>
    <td>{props.list.Book_Name}</td>
    <td>{props.list.Book_ISBN}</td>
    <td>{props.list.Book_Author}</td>
    <td>{props.list.Book_Price}</td>
    <td>{props.list.Book_PublishYear}</td>
    <td>{props.list.Book_Publisher}</td>
</tr>
);
export default class ViewBooks extends Component {
constructor(props){
    super(props);
    this.state={books:[]};
}
componentDidMount() {
    axios.get('http://localhost:3000/book/all').then((res)=>{
        this.setState({books:res.data});
    }).catch(function (error) {
        console.log(error);
    })
}
bookList()
{
    return this.state.books.map((book,i)=>{
        return <List book = {book} key={i}/>

    })

}

我无法从db检索值。由于Uncaught TypeError:this.state.books.map不是函数

,因此出现错误

0 个答案:

没有答案