<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>vue生命周期学习</title>
<script src="https://cdn.bootcss.com/vue/2.4.2/vue.js"></script>
</head> <body>
<div id="app">
<input v-model="message"></input>
<h1>{{message1}}</h1>
</div>
</body>
<script>
var vm = new Vue({/*创建vue对象*/
el: '#app',/****挂载目标****/
data: {/****数据对象****/
message: 'Hello World!'
},
computed:{/****实现某一属性的实时计算****/
message1:function(){
return this.message.split("").reverse().join("");
}
},
watched:{/****检测某一属性值的变化****/ },
methods:{/****组件内部的方法****/ }, beforeCreate: function() {
console.group('------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
},
/**
* 1.在beforeCreate和created钩子之间,程序开始监控Data对象数据的变化及vue内部的初始化事件
*
* */
created: function() {
console.group('------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); //已被初始化
},
/**
* 2.在created和beforeMount之间,判断是否有el选项,若有则继续编译,无,则暂停生命周期;
* 然后程序会判断是否有templete参数选项,若有,则将其作为模板编译成render函数。若无,则将外部html作为模板编译(template优先级比外部html高)
*
* */
beforeMount: function() {
console.group('------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); //已被初始化
},
/**
* 3.在beforeMount和mounted之间,程序将上一步编辑好的html内容替换el属性指向的dom对象或者选择权对应的html标签里面的内容
*
* */
mounted: function() {
console.group('------mounted 挂载结束状态------');
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); //已被初始化
},
/**
* 4.mounted和beforeUpdate之间,程序实时监控数据变化
*
* */
beforeUpdate: function() {
console.group('beforeUpdate 更新前状态===============》');
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);
},
/**
* 5.beforeUpdate和updated之间,实时更新dom
*
* */
updated: function() {
console.group('updated 更新完成状态===============》');
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);
},
beforeDestroy: function() {
console.group('beforeDestroy 销毁前状态===============》');
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);
},
/**
* 6.实例销毁
*
* */
destroyed: function() {
console.group('destroyed 销毁完成状态===============》');
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)
}
})
</script> </html>

最新文章

  1. Win10 UI入门 SliderRectangle
  2. Git Push 避免用户名和密码方法
  3. ZXing生成二维码
  4. Asp.net 加载事件(转载)
  5. 之前总结的今天给大分享一下iOS
  6. objective C 学习之02
  7. [转] Immutable 详解及 React 中实践
  8. 11.3 afternoon
  9. LINUX 网络编程 原始套接字
  10. linux shell 找端口号及对应的进程
  11. JFFS2文件系统的移植
  12. Erlang cowboy 处理不规范的客户端
  13. Redis数据结构之intset
  14. Angel - 模拟Kafka数据流调试FTRL的方法
  15. spring @transactional 注解事务
  16. web前端名词
  17. opencv学习之路(2)、读取视频,读取摄像头
  18. Hibernate中get()和load()的区别
  19. 转载:C++ typename的起源与用法
  20. [BZOJ4260]Codechef REBXOR(Trie)

热门文章

  1. OOP 面向对象 七大原则 (二)
  2. OOP 面向对象 七大原则 (一)
  3. XML文件基础
  4. 2015 Multi-University Training Contest 6 hdu 5357 Easy Sequence
  5. hdu 1702 栈和队列的简单应用
  6. ASP.NET - 单元测试
  7. mongodb 学习笔记 07 -- 数据备份、恢复
  8. Eclipse中高效的快捷键、调试及Junit
  9. COCOS2DX 3.0 优化提升渲染速度 Auto-batching
  10. Apache + Tomcat 负载均衡 session复制