Vue.js component lifecycle for children(Vue.js 子组件生命周期)
问题描述
子组件的创建和挂载顺序是什么?我知道单个组件的生命周期记录在
也看看 这篇文章由 LinusBorg 在 vuejs 论坛上发表.
<块引用>beforeCreate()
和父级的created()
先运行.- 然后父模板被渲染,这意味着子组件被创建.
- 所以现在孩子的
beforeCreate()
和created()
钩子分别执行. - 这些子组件挂载到 DOM 元素上,调用它们的
beforeMount()
和mounted()
钩子. - 只有在父模板完成后,父模板才能挂载到DOM,所以最后父节点的
beforeMount()
和mounted()
钩子是调用.
What order are child components created and mounted in? I know that the lifecycle for a single component is documented here, but I couldn't find anything that described when children were created and mounted.
For example, what is the creation and mounting order for the following component?
<template>
<div class='parent'>
<child-1/>
<child-2/>
<child-3/>
</div>
</template>
I found this article to be especially helpful in explaining the order of parent/child lifecycle hooks execution. This diagram in particular offers a nice summary of the process.
Also have a look at this post by LinusBorg on the vuejs forum.
beforeCreate()
andcreated()
of the parent run first.- Then the parent’s template is being rendered, which means the child components get created.
- so now the children’s
beforeCreate()
andcreated()
hooks execute respectively.- these child components mount to DOM elements, which calls their
beforeMount()
andmounted()
hooks.- and only then, after the parent’s template has finished, can the parent be mounted to the DOM, so finally the parent’s
beforeMount()
andmounted()
hooks are called.
这篇关于Vue.js 子组件生命周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Vue.js 子组件生命周期
基础教程推荐
- Chart.js 在线性图表上拖动点 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 直接将值设置为滑块 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01