Skip to content

vue

  1. beforeCreate ( <=初始化事件和生命周期)
  2. created (<= prop 注入完成)
  3. beforeMount 编译 template 模板或者 render, 并收集依赖
  4. mouted (挂载到 dom 上面)
  5. beforeUpdate => 不能在里面更新 data => 开始 diff render
  6. beforeDestory => 解除绑定,解除事件,销毁子组件。
  7. destoryed => 删除完回调

react

初始化阶段

  1. defaultProp => prop
  2. initState
  3. componentWillMount
  4. render
  5. componentDidMount

运行阶段

react 的变化需要自己手动更新,包括 props 和 state 的变化

  1. props 变化通过 componentWillReceiveProps 获得,
  2. state 的变化通过 setState 方法来实现

均会触发 shouldComponentUpdate 钩子,如果钩子返回 false 表示不更新。
然后会触发 componentWillUpdate 构造
重新调用 render 函数, 渲染界面
触发 componentDidUpdate 钩子,

销毁钩子 componentWillUnmount