路由跳转后,因为还是同一个组件,不会触发componentDidMount,所以我在componentWillReceiveProps里进行处理了。
路由跳转后,因为还是同一个组件,不会触发componentDidMount,所以我在componentWillReceiveProps里进行处理了。
10 回答11.2k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.7k 阅读✓ 已解决
3 回答1.9k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
先把
componentWillReceiveProps
的生命周期搞清楚。componentWillReceiveProps
方法中,要通过nextProps
来改变state
.你setState
的那个值,与nextProps
毛关系都没有,当然子组件不更新了。另外,
props
也可以render
,所以不需要componentWillReceiveProps
,直接在render
中,根据props
实现就好了。