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

    它可以总共分为8个阶段:

    beforeCreate(创建前),

    created(创建后),

    beforeMount(载入前),

    mounted(载入后),

    beforeUpdate(更新前),

    updated(更新后),

    beforeDestroy(销毁前),

    destroyed(销毁后)

    然后用一个实例的demo 来演示一下具体的效果:

    <div id=app>{{a}}</div>

    <script>

    var myVue = new Vue({          

    el: "#app",          

    data: {

    a: "Vue.js"        

    },         

     beforeCreate: function() { 

              console.log("创建前")            

    console.log(this.a)            

    console.log(this.$el)          

    },         

     created: function() {

                    console.log("创建之后");            

    console.log(this.a)            

    console.log(this.$el)          

    },         

     beforeMount: function() {            

    console.log("mount之前")            

    console.log(this.a)            

    console.log(this.$el)          

    },          

    mounted: function() {            

    console.log("mount之后")            

    console.log(this.a)            

    console.log(this.$el)          

    },          

    beforeUpdate: function() {            

    console.log("更新前");            

    console.log(this.a)            

    console.log(this.$el)          

    },          

    updated: function() {            

    console.log("更新完成");            

    console.log(this.a);            

    console.log(this.$el)          

    },          

    beforeDestroy: function() {            

    console.log("销毁前");            

    console.log(this.a)            

    console.log(this.$el)            

    console.log(this.$el)          

    },          

    destroyed: function() {           

    console.log("已销毁");          

    console.log(this.a)          

    console.log(this.$el)          

    }   

      });  

    </script>

     

     在beforeUpdate,可以监听到data的变化但是view层没有被重新渲染,view层的数据没有变化。等到updated的时候 view层才被重新渲染,数据更新。

  • 相关阅读:
    sql2005创建存储过程
    sql 2005 调用存储过程
    sql2005创建存储过程(需要注意的几点)
    c# 日期处理
    Worldwind WMS Server安装
    Ubuntu11.10 设置默认Terminal为Terminator
    WordPress中文标题无法显示的解决方法
    Unknown Source的出现及解决
    Windows下 ant配置 以及 Unable to locate tools.jar
    安装WordPress中文包四步曲
  • 原文地址:https://www.cnblogs.com/panzai/p/12653649.html
Copyright © 2011-2022 走看看