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

    1.用Vue框架,熟悉它的生命周期可以让开发更好的进行。

    2.下面是官网详细的给出了vue的生命周期:

    3.它可以总共分为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>

    4.代码运行结果:

  • 相关阅读:
    `cd -`
    .git文件夹过大的解决方法
    避免对函数参数的修改
    2020年10月 修改Ant Design Pro底部版权信息的方法
    度目-人脸应用套件 文档中的坑
    "A little like that j-thing"
    Linux安装MySQL后设置密码
    append对len和cap的影响
    s := []int{0, 1, 2, 3, 8: 100}
    Python学习笔记
  • 原文地址:https://www.cnblogs.com/zhengao/p/6719841.html
Copyright © 2011-2022 走看看