Vue生命周期钩子函数加载顺序

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-18 03:37:57

首先创建子组件

<template>
    <div>
      <span>我是子组件</span>
    </div>
</template>

<script>
export default {
  name: "Children",
  data() {
    return {
    
    }
  },
  beforeCreate() {
    console.log("子组件beforeCreate")
  },
  created() {
    console.log("子组件created")
  },
  beforeMount() {
    console.log("子组件beforeMount")
  },
  mounted() {
    console.log("子组件mounted")
  },
  beforeUpdate() {
    console.log("子组件beforeUpdate")
  },
  updated() {
    console.log("子组件updated")
  },
  beforeDestroy() {
    console.log("子组件beforeDestroy")
  },
  destroyed() {
    console.log("子组件destroyed")
  }
}
</script>

将子组件引入在父组件中使用

<template>
  <div>
    <children></children>
  </div>
</template>

<script>
  import children from "./Children"
export default {
  name: '',
  components: { children },
  data () {
    return {
    }
  },
  beforeCreate() {
    console.log("父组件beforeCreate")
  },
  created() {
    console.log("父组件created")
  },
  beforeMount() {
    console.log("父组件beforeMount")
  },
  mounted() {
    console.log("父组件mounted")
  },
  beforeUpdate() {
    console.log("父组件beforeUpdate")
  },
  updated() {
    console.log("父组件updated")
  },
  beforeDestroy() {
    console.log("父组件beforeDestroy")
  },
  destroyed() {
    console.log("父组件destroyed")
  },
  methods: {}
}
</script>

查看控制台钩子函数加载顺序
在这里插入图片描述

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!