首页 > 其他 > 详细

vue钩子函数

时间:2020-06-26 23:19:00      阅读:88      评论:0      收藏:0      [点我收藏+]
 
 
官方截图,及参数:
技术分享图片

 

 

 

技术分享图片

 

 

 

 

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/vue/2.1.3/vue.js"></script>
</head>
<body>
 
<div id="app">
     <p>{{ message }}</p>
</div>
 
<script type="text/javascript">
     
 
  var app = new Vue({
      el: #app,
      data: {
          message : "xuxiao is boy"
      },
       beforeCreate: function () {
                console.group(beforeCreate 创建前状态===============》);
               console.log( "el     : " + this.$el); //undefined
               console.log("data   : " + this.$data); //undefined
               console.log("message: " + this.message)
        },
        created: function () {
            console.group(created 创建完毕状态===============》);
            console.log("el     : " + this.$el); //undefined
               console.log("data   : " + this.$data); //已被初始化
               console.log("message: " + this.message); //已被初始化
        },
        beforeMount: function () {
            console.group(beforeMount 挂载前状态===============》);
            console.log("el     : " + (this.$el)); //已被初始化
            console.log(this.$el);
               console.log("data   : " + this.$data); //已被初始化
               console.log("message: " + this.message); //已被初始化
        },
        mounted: function () {
            console.group(mounted 挂载结束状态===============》);
            console.log("el     : " + this.$el); //已被初始化
            console.log(this.$el);   
               console.log("data   : " + this.$data); //已被初始化
               console.log("message: " + this.message); //已被初始化
        },
        beforeUpdate: function () {
            console.group(beforeUpdate 更新前状态===============》);
            console.log("el     : " + this.$el);
            console.log(this.$el);  
               console.log("data   : " + this.$data);
               console.log("message: " + this.message);
        },
        updated: function () {
            console.group(updated 更新完成状态===============》);
            console.log("el     : " + this.$el);
            console.log(this.$el);
               console.log("data   : " + this.$data);
               console.log("message: " + this.message);
        },
        beforeDestroy: function () {
            console.group(beforeDestroy 销毁前状态===============》);
            console.log("el     : " + this.$el);
            console.log(this.$el);   
               console.log("data   : " + this.$data);
               console.log("message: " + this.message);
        },
        destroyed: function () {
            console.group(destroyed 销毁完成状态===============》);
            console.log("el     : " + this.$el);
            console.log(this.$el);
               console.log("data   : " + this.$data);
               console.log("message: " + this.message)
        }
    })
</script>
</body>
</html>

 

 

 
 
附带测试地址:http://jsrun.net/6YXKp/edit
 
根据控制台打印了解各个钩子函数调用顺序以及使用方法:
 
技术分享图片
 
 
 
 
 

vue钩子函数

原文:https://www.cnblogs.com/971125zhang/p/13196579.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!