一、实例代码

父组件:

<template>
<div id="parent">
<child></child>
</div>
</template> <script>
import child from './components/child'
export default {
name: 'parent',
components: {
child
},
beforeCreate() {
console.log('I am parents beforeCreated');
},
created() {
console.log('I am parents created');
},
beforeMount() {
console.log('I am parents beforeMount');
},
mounted() {
console.log('I am parents mounted');
}
}
</script>

子组件:

<template>
<div class="child">
child
</div>
</template> <script>
export default {
name: 'child',
beforeCreate() {
console.log('I am child beforeCreated');
},
created() {
console.log('I am child created');
},
beforeMount() {
console.log('I am child beforeMount');
},
mounted() {
console.log('I am child mounted');
}
}
</script>

执行结果:

二、结论

我们从而可以得出父子组件的执行顺序为:

  • 父组件beforeCreated
  • 父组件created
  • 父组件beforeMounted
  • 子组件beforeCreated
  • 子组件created
  • 子组件beforeMounted
  • 子组件mounted
  • 父组件mounted

注意:

  • 父组件的mounted是在最后执行的。
  • 因此在子组件的mounted中渲染父组件在mounted阶段请求的数据,是会无反应的。因为子组件mounted渲染数据会发生在父组件mounted请求数据之前。

Vue相关,vue父子组件生命周期执行顺序。的更多相关文章

  1. vue父子组件生命周期执行顺序

    之前写了vue的生命周期,本以为明白了vue实例在创建到显示在页面上以及销毁等一系列过程,以及各个生命周期的特点.然而今天被问到父子组件生命周期执行顺序的时候一头雾水,根本不知道怎么回事.然后写了一段 ...

  2. Vue父子组件生命周期执行顺序及钩子函数的个人理解

    先附一张官网上的vue实例的生命周期图,每个Vue实例在被创建的时候都需要经过一系列的初始化过程,例如需要设置数据监听,编译模板,将实例挂载到DOM并在数据变化时更新DOM等.同时在这个过程中也会运行 ...

  3. vue父子组件生命周期函数执行顺序

    vue父组件加载和销毁执行最后一个钩子函数之前先执行一遍子组件的钩子: 1.加载 父:beforecreate-created-beforeMount-(子:beforecreate-created- ...

  4. vue中父子组件钩子的执行顺序

    我们已经非常熟悉单个的vue组件的生命周期执行顺序了,但是,如果有嵌套组件,父子组件的生命周期的执行顺序是什么? 当父子组件在加载的时候,执行的先后顺序为 父beforeCreate -> 父c ...

  5. React生命周期执行顺序详解

    文章内容转载于https://www.cnblogs.com/faith3/p/9216165.html 一.组件生命周期的执行次数是什么样子的??? 只执行一次: constructor.compo ...

  6. Vue父子组件生命周期

    转载自:https://blog.csdn.net/a8725585/article/details/79092505 vue父子组件钩子函数触发顺序 beforeMount后mounted前构造子组 ...

  7. activity生命周期分析(两个activity之间跳转的生命周期执行顺序)

    NoteMainActivity点击跳转至NoteListActivity 我们都了解: 当A界面点击进入B界面时,此时         A===onPause--->onStop       ...

  8. flex 组件重写 组件生命周期

    AS方式重写组件常规步骤 1.如果有必要,为组件创建所有基于标记(tag-based)的皮肤(skins) 2.创建ActionScript类文件 ⑴从一个基类扩展,比如UIComponent或者其他 ...

  9. vue 父子component生命周期

    如今前端框架都流行组件化,页面元素都可以使用组件进行高度概括,那么处理组件之间的关系就如同处理页面架构一样重要.正确理解组件之间的关系,才能让代码按照我们与预料方式工作.最近参与了一个Vue.js的项 ...

随机推荐

  1. hdu 5185 Equation(分析+DP)

    题意: Gorwin is very interested in equations. Nowadays she gets an equation like thisx1+x2+x3+⋯+xn=n, ...

  2. Zabbix webhook 自定义报警媒介

    场景一:使用企业微信机器人报警 图中的token是:在群组中添加机器人,机器人的webhook地址的key var Wechat = { token: null, to: null, message: ...

  3. 编译安装与gcc编译器

    先说一下gcc编译器,只知道这是一个老款的编译器.编译的目的也比较重要,就是将c语言的代码编译成可以执行的binary文件. gcc 简单使用(后期补充) eg: gcc example.c    # ...

  4. You (oracle) are not allowed to access to (crontab) because of pam configura

    用oracle用户添加备份计划任务,crontab -e,提示:You (oracle) are not allowed to access to (crontab) because of pam c ...

  5. [命令行]Mysql 导入 excel 文件

    将 excel 表格中的数据批量导入数据库中 将要导入的表删除字段名,只留下要导入的数据. 将文件另存为 *.csv格式,可以用记事本打开(实际上就是标准的逗号分隔的数据 进入mysql,输入命令,打 ...

  6. CSS 海盗船加载特效

    CSS 海盗船加载特效 <!DOCTYPE html> <html lang="en"> <head> <meta charset=

  7. restTemple发送请求、上传文件(@LoadBalanced微服务调用及url调用)

    import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Co ...

  8. Windows内核中的CPU架构-7-陷阱门(32-Bit Trap Gate)

    Windows内核中的CPU架构-7-陷阱门(32-Bit Trap Gate) 陷阱门和中断门几乎是一模一样的: (注:图里高32位中的第11位的值为D,其实是1) 除了高32位中的type字段的内 ...

  9. [bzoj1084]最大子矩阵

    用f[i][j][k]表示第一行前i个数,第二行前j个数选k个子矩形的答案,考虑转移:1.在第一行/第二行选择一个矩形2.当i=j时,可以选择一个两行的矩形注意要特判m=1的情况 1 #include ...

  10. LifseaOS 悄然来袭,一款为云原生而生的 OS

    作者:黄韶宇.初扬 审核&校对:溪洋.海珠 编辑&排版:雯燕 LifseaOS 在刚刚过去的云栖大会上,一款新的 Linux Base 操作系统悄悄发布,它就是 LifseaOS(Li ...