vue生命周期-父子组件

vue生命周期-父子组件

vue父子组件的生命周期

创建实例:从外到内(从父组件到子组件)

渲染:从内到外(子组件渲染完,再渲染父组件)

Vue.component('comp',{
  template:'<div>This is a component !</div>'
})
const app = new Vue({
  render:h => h(App)
})
app.$mount('#app')
// new Vue({el:'#app'})

创建(从外到内)到挂载(从内到外)阶段

  • root beforeCreate
    • root created
      • root beforeMount
      • 这里root组件尝试进行挂载,在compile阶段,不管是原生标签div还是组件标签comp,是不会进行特殊处理的, compileToFuction函数返回一个render函数,这个render函数中是不会对组件标签进行特殊处理的。一直到moutComponent方法中更新函数updateComponent = () => {vm._update(vm._render(),hydrating)}被调用,render函数执行的时候,会生成vnode,在这里进行判断:原始标签 还是 组件标签。如果发现不是原始标签,即使组件标签:
      • comp beforeCreate
    • comp created
  • comp beforeMount
  • comp mounted
  • root mounted

更新阶段

  • root beforeUpdate
    • comp beforeUpdate
    • comp updated
  • root updated

销毁阶段

  • root beforeDestroy
    • comp beforeDestroy
    • comp destroyed
  • root destroyed

Vue生命周期

image

posted @   shine_lovely  阅读(164)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示