You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
总计中写道:
总结
我们一般会把组件的 state 的初始化工作放在 constructor 里面去做;在 componentWillMount 进行组件的启动工作,例如 Ajax 数据拉取、定时器的启动;组件从页面上销毁的时候,有时候需要一些数据的清理,例如定时器的清理,就会放在 componentWillUnmount 里面去做。
也就是说,推荐在 componentWillMount 的时候进行数据请求。我在翻 react 文档的时候发现,上面是这么写的:
componentDidMount()
componentDidMount() is invoked immediately after a component is mounted. Initialization that requires DOM nodes should go here. If you need to load data from a remote endpoint, this is a good place to instantiate the network request. Setting state in this method will trigger a re-rendering.
文档上说应该在 componentDidMount 阶段进行网络请求的实例化,那请问最好的进行网络请求的地方是在哪里?
The text was updated successfully, but these errors were encountered:
总计中写道:
总结
我们一般会把组件的 state 的初始化工作放在 constructor 里面去做;在 componentWillMount 进行组件的启动工作,例如 Ajax 数据拉取、定时器的启动;组件从页面上销毁的时候,有时候需要一些数据的清理,例如定时器的清理,就会放在 componentWillUnmount 里面去做。
也就是说,推荐在 componentWillMount 的时候进行数据请求。我在翻 react 文档的时候发现,上面是这么写的:
componentDidMount()
componentDidMount() is invoked immediately after a component is mounted. Initialization that requires DOM nodes should go here. If you need to load data from a remote endpoint, this is a good place to instantiate the network request. Setting state in this method will trigger a re-rendering.
文档上说应该在 componentDidMount 阶段进行网络请求的实例化,那请问最好的进行网络请求的地方是在哪里?
The text was updated successfully, but these errors were encountered: