继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

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

记得丶微笑
关注TA
已关注
手记 7
粉丝 1
获赞 4

执行顺序:beforeCreate->父created->父beforeMount->子beforeCreate->子created->子beforeMount->子mounted->父mounted。

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="./lib/vue-2.4.0.js"></script>
</head>

<body>
  <div id="app">
    <login></login>
  </div>

  <script>
    var login = {
      template: '<h1>{{childMsg}}}</h1>',
      data(){
        return {
          childMsg:'child'
        }
      },  
      beforeCreate: function () {
        debugger;
        console.log("子组件的beforeCreate")
      },
      created: function () {
        debugger
        console.log("子组件的created")
      },
      beforeMount: function () {
        debugger
        console.log("子组件的beforeMount")
      },
      mounted: function () {
        debugger
        console.log("子组件的mounted")
      }
    }

    var vm = new Vue({
      el: '#app',
      data: {
        fatherMsg: "father"
      },
      methods: {},
      components: {
        login
      },
      beforeCreate: function () {
        debugger
        console.log("父组件的beforeCreate")
      },
      created: function () {
        debugger
        console.log("父组件的created")
      },
      beforeMount: function () {
        debugger
        console.log("父组件的beforeMount")
      },
      mounted: function () {
        debugger
        console.log("父组件的mounted")
      },
    });
  </script>
</body>

</html>
打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP