zoukankan      html  css  js  c++  java
  • vue生命周期函数

    Vue生命周期函数是vue实例在某一时间点会自动执行的函数

    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4.     <title></title>
    5.     <script type="text/javascript" src="https://cdn.jsdelivr.net/vue/2.1.3/vue.js"></script>
    6. </head>
    7. <body>
    8.  
    9. <div id="app">
    10.      <p>{{ message }}</p>
    11. </div>
    12.  
    13. <script type="text/javascript">
    14.  
    15.   var app = new Vue({
    16.       el: '#app',
    17.       data: {
    18.           message : "xuxiao is boy"
    19.       },
    20.        beforeCreate: function () {
    21.                 console.group('beforeCreate 创建前状态===============》');
    22.                console.log("%c%s", "color:red" , "el : " + this.$el); //undefined
    23.                console.log("%c%s", "color:red","data : " + this.$data); //undefined
    24.                console.log("%c%s", "color:red","message: " + this.message)
    25.         },
    26.         created: function () {
    27.             console.group('created 创建完毕状态===============》');
    28.             console.log("%c%s", "color:red","el : " + this.$el); //undefined
    29.                console.log("%c%s", "color:red","data : " + this.$data); //已被初始化
    30.                console.log("%c%s", "color:red","message: " + this.message); //已被初始化
    31.         },
    32.         beforeMount: function () {
    33.             console.group('beforeMount 挂载前状态===============》');
    34.             console.log("%c%s", "color:red","el : " + (this.$el)); //已被初始化
    35.             console.log(this.$el);
    36.                console.log("%c%s", "color:red","data : " + this.$data); //已被初始化
    37.                console.log("%c%s", "color:red","message: " + this.message); //已被初始化
    38.         },
    39.         mounted: function () {
    40.             console.group('mounted 挂载结束状态===============》');
    41.             console.log("%c%s", "color:red","el : " + this.$el); //已被初始化
    42.             console.log(this.$el);
    43.                console.log("%c%s", "color:red","data : " + this.$data); //已被初始化
    44.                console.log("%c%s", "color:red","message: " + this.message); //已被初始化
    45.         },
    46.         beforeUpdate: function () {
    47.             console.group('beforeUpdate 更新前状态===============》');
    48.             console.log("%c%s", "color:red","el : " + this.$el);
    49.             console.log(this.$el);
    50.                console.log("%c%s", "color:red","data : " + this.$data);
    51.                console.log("%c%s", "color:red","message: " + this.message);
    52.         },
    53.         updated: function () {
    54.             console.group('updated 更新完成状态===============》');
    55.             console.log("%c%s", "color:red","el : " + this.$el);
    56.             console.log(this.$el);
    57.                console.log("%c%s", "color:red","data : " + this.$data);
    58.                console.log("%c%s", "color:red","message: " + this.message);
    59.         },
    60.         beforeDestroy: function () {
    61.             console.group('beforeDestroy 销毁前状态===============》');
    62.             console.log("%c%s", "color:red","el : " + this.$el);
    63.             console.log(this.$el);
    64.                console.log("%c%s", "color:red","data : " + this.$data);
    65.                console.log("%c%s", "color:red","message: " + this.message);
    66.         },
    67.         destroyed: function () {
    68.             console.group('destroyed 销毁完成状态===============》');
    69.             console.log("%c%s", "color:red","el : " + this.$el);
    70.             console.log(this.$el);
    71.                console.log("%c%s", "color:red","data : " + this.$data);
    72.                console.log("%c%s", "color:red","message: " + this.message)
    73.         }
    74.     })
    75. </script>
    76. </body>
    77. </html>

    beforecreatedel data 并未初始化 
    created:完成了 data 数据的初始化,el没有
    beforeMount:完成了 el data 初始化 
    mounted :完成挂载

  • 相关阅读:
    Java代码检测工具
    java编程工具
    100-days: The one day
    前端书籍整理
    vue 学习笔记(二)
    从零开始写一个npm包及上传
    Vue Baidu Map 插件的使用
    对数组对象进行过滤
    使用css方法使footer保持在页面的最底部
    判断是第一次打开界面?还是刷新
  • 原文地址:https://www.cnblogs.com/wangyawei/p/8898115.html
Copyright © 2011-2022 走看看