React有哪些生命周期钩子函数?数据请求放在哪个钩子里? undefined_AlvinLin 2022-12-24 196 阅读1分钟 注意:函数式组件没有生命周期 挂载时调用 constructor,更新时不调用 更新时调用 shouldComponentUpdate 和 getSnapshotBeforeUpdate,挂载时不调用 should... 在 render 前调用,getSnapshot... 在 render 后调用 请求放在 componentDidMount 里。 constructor不能放ajax请求是因为它会在ssr的时候被调用,服务器端拿不到数据 放在中间(render)可能会触发无限调用