生命周期图示

  • 创建前,创建后,挂载前,挂载后,更新前,更新后,销毁前,销毁后

beforeCreate:function(){
console.log('1-beforeCreate 组件还未被创建');
},
created:function(){
console.log('2-created 组件已被创建');
},
beforeMount:function(){
console.log('3-beforeMount 组件已创建但还未挂载到DOM节点上');
},
mounted:function(){
console.log('4-mounted 组件已挂载到DOM节点上');
},
beforeUpdate:function(){
console.log('5-beforeUpdate 数据更新前');
},
updated:function(){
console.log('6-updated 被更新后');
},
activated:function(){
console.log('7-activated');
},
deactivated:function(){
console.log('8-deactivated');
},
beforeDestroy:function(){
console.log('9-beforeDestroy 组件即将被销毁');
},
destroyed:function(){
console.log('10-destroyed 组件已经被销毁')
}

<button onclick='app.$destroy()'>销毁</button>

$el、$data

created和mounted

  • beforeCreate:el和data并未初始化

  • created:完成了data数据的初始化,el没有

  • beforeMount: 完成了el和data初始化

  • mounted: 完成挂载

      beforeCreate:function(){
    console.log('1-beforeCreate 组件还未被创建');
    console.log("%c%s", "color:red" , "el : " + this.$el); //undefined
    console.log("%c%s", "color:red","data : " + this.$data); //undefined
    console.log("%c%s", "color:red","message: " + this.message)//undefined
    }

	created:function(){
console.log('2-created 组件已被创建');
console.log("%c%s", "color:red","el : " + this.$el); //undefined
console.log("%c%s", "color:red","data : " + this.$data); //已被初始化
console.log("%c%s", "color:red","message: " + this.message); //已被初始化
}

	beforeMount:function(){
console.log('3-beforeMount 组件已创建但还未挂载到DOM节点上');
console.log("%c%s", "color:red","el : " + (this.$el)); //undefined
console.log(this.$el);
console.log("%c%s", "color:red","data : " + this.$data); //已被初始化
console.log("%c%s", "color:red","message: " + this.message); //已被初始化
}
  • beforeMount 在.vue文件中el还没被创建

            beforeMount: function () {
console.log('beforeMount 挂载前状态===============》');
console.log("%c%s", "color:red","el : " + (this.$el));//已被初始化
console.log(this.$el);
console.log("%c%s", "color:red","data : " + this.$data);//已被初始化
console.log("%c%s", "color:red","message: " + this.message);//已被初始化
}
  • beforeMount在html文件中el已被初始化

	mounted:function(){
console.log('4-mounted 组件已挂载到DOM节点上');
console.log("%c%s", "color:red","el : " + this.$el); //已被初始化
console.log(this.$el);
console.log("%c%s", "color:red","data : " + this.$data); //已被初始化
console.log("%c%s", "color:red","message: " + this.message); //已被初始化
}

最新文章

  1. 【SharePoint学习笔记】第1章 SharePoint Foundation开发基础
  2. WinForm------点击Control弹出MessageBox
  3. Android项目结构 以及体系结构
  4. 细雨学习笔记:Jmeter集合点
  5. enter mysql
  6. 玩转图片Base64编码
  7. nyoj89 汉诺塔(二)
  8. The APR based Apache Tomcat Native library
  9. Flash上传组件之SWFUpload文件上传
  10. spring-mvc.xml配置文件出错
  11. 【转】如何过滤 adb logcat 输出
  12. SOA一些资料
  13. iOS之PCH文件
  14. STM32.BOOT
  15. oracle以逗号分隔查询结果列表
  16. bazel-编译静态库
  17. bootstrap+PHP表单验证
  18. 使用select多选标签笔记
  19. SSH基本概念和用途
  20. 洛谷 P3224 [HNOI2012]永无乡 解题报告

热门文章

  1. Unable to open connection to &quot;Microsoft SQL Server, provider V1.0.5000.0 in framework
  2. I/O复用----select
  3. [SCOI2007]修车 费用流
  4. UVA.725 Division (暴力)
  5. 51nod 1196 字符串的数量(DP+数论?)
  6. [vim]大小写转换
  7. boost文件锁的使用
  8. 移动端1px边框问题
  9. jquery禁用按钮
  10. 编译redis时 提示make cc Command not found