vue 生命周期

 

 vue 生命周期图

 

 实验

 
 
<section id="app-8"> {{data}} </section>

var
myVue=new Vue({ el:"#app-8", data:{ data:"aaaaa", info:"nono" }, beforeCreate:function(){ console.log("建立前========") console.log(this.data) console.log(this.$el) }, created:function(){ console.log("已建立========") console.log(this.info) console.log(this.$el) }, beforeMount:function(){ console.log("mount以前========") console.log(this.info) console.log(this.$el) }, mounted:function(){ console.log("mounted========") console.log(this.info) console.log(this.$el) }, beforeUpdate:function(){ console.log("更新前========"); }, updated:function(){ console.log("更新完成========"); }, beforeDestroy:function(){ console.log("销毁前========") console.log(this.info) console.log(this.$el) }, destroyed:function(){ console.log("已销毁========") console.log(this.info) console.log(this.$el) } })

 

------

知识点

由上图可知:

  一、beforeCreate 此时$el、data 的值都为undefinedhtml

  二、建立以后,此时能够拿到data的值,可是$el依旧为undefinedvue

  三、mount以前,$el的值为“虚拟”的元素节点app

  四、mount以后,mounted以前,“虚拟”的dom节点被真实的dom节点替换,并将其插入到dom树中,因而在触发mounted时,能够获取到$el为真实的dom元素()dom

  myVue.$el===document.getElementById("app-8")  // truethis

 

接着,在console中修改data,更新视图spa

 

 

   触发beforeUpdata 和updatedcode

 

  接着,执行myVue.$destroy()htm

 

 总结一下,对官方文档的那张图简化一下,就获得了这张图

 

 文章中如有错误请指出,转载请注明出处,谢谢~blog

 原文
原文
https://www.cnblogs.com/gagag/p/6246493.html
相关文章
相关标签/搜索