• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
忆百合
博客园    首页    新随笔    联系   管理    订阅  订阅

Vue父子组件之间生命周期钩子函数的执行顺序

父子组件渲染顺序:

       父级beforeCreate

               ︾   

        父级create

                ︾ 

         父级beforeMount

                ︾

 

              子级beforeCreate

                     ﹀

             子级create

                    ﹀

             子级beforeMount

                    ﹀

            子级mounted

 

             ︾

      父级mounted

 

 

父子组件更新顺序:每个组件都会有一个组件自己的局部作用域,其局部作用域与父级的局部作用域、子级的局部作用域不会互相影响,所以子组件模板中的变量发生变化时只会触发子组件的beforeUpdate和updated,并不会触发父组件的beforeUpdate和updated;

父组件的更新顺序:

        父级mounted

               ︾

        父级beforeUpdate

                ︾

        父级updated

子组件的更新顺序:

        父级mounted

               ︾

 

              子级beforeUpdate

                     ﹀

              子级updated

 

 

子组件的销毁顺序:子级组件销毁时会触发父级组件beforeUpdate、updated,也会触发子级组件和孙子级组件的beforeDestroy、destroyed,但是不会触发子级组件的beforeUpdate、updated;

        父级mounted

               ︾

        父级beforeUpdate

               ︾

 

              子级beforeDestroy

                      ﹀

 

                     孙子级组件beforeDestroy

                            ︾

                     孙子级组件destroyed

    

                     ﹀

             子级destroyed

 

              ︾

      父组件updated

posted @ 2021-08-24 13:39  忆百合  阅读(422)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3