【发布时间】:2017-10-02 07:49:12
【问题描述】:
我使用这个to方法来处理组件,componentWillMount初始化主页的数据,当路由器更改(类别页面)时使用componentWillReceiveProps,但是当我从类别页面返回主页时,我知道因为componentWillMount只做一次所以我看不到数据。
componentWillMount(){
this.props.fetchBooks(1)
}
componentWillReceiveProps(nextProps){
if(nextProps.match.params.id && nextProps.match.params.id !== this.props.match.params.id){
this.props.fetchBookByCategory(nextProps.match.params.id)
}
}
我把这个初始化的代码放到componentWillReceiveProps中,它可以工作,但它会不断调用fetchBooks(1),尽管我试图处理一些条件,请帮我解决这个问题,非常感谢。
【问题讨论】: