Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于第二阶段 19.挂载阶段的组件生命周期(二)中 componentWillMount 的问题 #15

Open
dongliang1993 opened this issue Jul 10, 2017 · 0 comments

Comments

@dongliang1993
Copy link

总计中写道:
总结
我们一般会把组件的 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 阶段进行网络请求的实例化,那请问最好的进行网络请求的地方是在哪里?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant