我理解的vue生命周期
说些题外话,引出vue的生命周期。
比如人出生到寿终正寝,这是人的一个生命周期。他会经历出生,婴儿时期,童年时期,少年时期,青年,中年,老年,到 end。然后,每个时期都会有一定的历史任务在等着去完成,比如童年的时候,我们要学会基本的说话走路等,少年时期要完成一定量的识字识数等,青年要参与社会工作等,老年养老等。最重要的时期就是在青年和中年的时期,因为这个时期我们要实现个人的历史价值,完成一定的社会任务等。vue实例的时候,也是经历一定的生命周期,这个生命周期会有对应的钩子函数。好了,下面就是我自己对生命周期的理解。
这个图是vue 官网的一张解释生命周期的一张图,我们将会根据这个图来做下demo理解, Provide the img of vue's lifecircle.

var app = new Vue({
el: '#app',
data: {
message : "vue life-circle" ,
},
beforeCreate: function () {
console.log('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) ;
},
created: function () {
console.log('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('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); //已被初始化
},
mounted: function () {
console.log('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); //已被初始化
this.message = 'message is change'; // 在mounted 改变数据 触发下面的beforeUpdate的方法
},
beforeUpdate: function () {
console.log('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);
this.message = 'message is change';
console.log('change', this.message)
},
updated: function () {
console.log('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.log('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);
this.message = 'message change again';
console.log('change', this.message)
},
destroyed: function () {
console.log('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)
console.log('change again', this.message)
}
})
destroyed 的两个方法 需要在控制台里面 调用, app.destroyed()
《未完,待续。。。》 参考文章: https://segmentfault.com/a/1190000008010666
我理解的vue生命周期的更多相关文章
- vue生命周期的理解
我从官网上下载了一张vue生命周期的图,接下来实际分析一波vue到底执行了什么东西. 1.我们在使用vue时必不可少的操作就是 var vm = new Vue({}),这样我们就创建了一个vue的实 ...
- 详解vue生命周期
vue生命周期 @(vue)[生命周期] 前言 在使用vue一个多礼拜后,感觉现在还停留在初级阶段,虽然知道怎么和后端做数据交互,但是对于mounted这个挂载还不是很清楚的.放大之,对vue的生命周 ...
- Vue生命周期,面试常见问题
一.对于MVVM的理解? MVVM 是 Model-View-ViewModel 的缩写.Model代表数据模型,也可以在Model中定义数据修改和操作的业务逻辑.View 代表UI 组件,它负责将数 ...
- 【Vue笔记】-- 详解vue生命周期
针对于Vue的生命周期进行详细的说明,方面加深对各个方法的引用. 引言: 前几天重新回顾vue官网时,看到vue的生命周期,想着自己用vue开发了快一年了,就总结总结vue知识,再次加深自己对vue的 ...
- 面试题之(vue生命周期)
在面试的时候,vue生命周期被考察的很频繁. 什么是vue生命周期呢? Vue实例有一个完整的生命周期,也就是从开始创建.初始化数据.编译模板.挂载Dom.渲染→更新→渲染.卸载等一系列过程,我们称这 ...
- vue生命周期图示中英文版Vue实例生命周期钩子
vue生命周期图示中英文版Vue实例生命周期钩子知乎上近日有人发起了一个 “react 是不是比 vue 牛皮,为什么?” 的问题,Vue.js 作者尤雨溪12月4日正面回应了该问题.以下是尤雨溪回复 ...
- vue生命周期钩子
转载自:https://segmentfault.com/a/1190000008010666?utm_source=tag-newest https://segmentfault.com/a/119 ...
- 理解mpvue的生命周期
mpvue是美团基于vue开发的一个开发小程序的框架,从而以vue的语法来开发小程序.在生命周期上,mpvue同时支持了vue的生命周期和小程序的生命周期,这可能让新上手的同学费解.这篇文章就来讲讲m ...
- VUE自定义指令生命周期,VUE生命周期
一.自定义指令的生命周期 自定义指令有五个生命周期(也叫钩子函数),分别是 bind,inserted,update,componentUpdated,unbind bind:只调用一次,指令第一次绑 ...
随机推荐
- PHP 图片验证码验证
*.html <input type="> <img src="> api.php <?php session_start(); $dataObj = ...
- 如何实现从 Redis 中订阅消息转发到 WebSocket 客户端
PHP 的redis扩展是阻塞式 IO ,使用订阅/发布模式时,会导致整个进程进入阻塞.因此必须使用Swoole\Redis异步客户端来实现. 实例代码 $server = new swoole_we ...
- ubuntu安装GBK编码
1 添加GBK编码 sudo vim /var/lib/locales/supported.d/local en_US.UTF-8 UTF-8 zh_CN.UTF-8 UTF-8 zh_CN.GBK ...
- Spring中的@Transactional(rollbackFor = Exception.class)属性详解
序言 今天我在写代码的时候,看到了.一个注解@Transactional(rollbackFor = Exception.class),今天就和大家分享一下,这个注解的用法: 异常 如下图所示,我们都 ...
- NFS网络共享文件系统
1.nfs服务端配置操作 1.1 创建所需的共享目录--源 mkdir /data/rw #rw代表同步的数据可读可写 1.2 对共享目录进行授权 chown -R nfsnobody.nfsno ...
- UOJ #276「清华集训2016」汽水
为什么你们常数都这么小啊 UOJ #276 题意:在树上找一条链使得|边权平均值$ -k$|尽量小,$ n<=5e4$ $ Solution:$ 首先二分答案$ ans$,即我们需要找一条链使得 ...
- centos 6.8下载地址
centos6.8校验码查询网站:https://wiki.centos.org/zh-tw/Manuals/ReleaseNotes/CentOS6.8 CentOS 6.8 64位DVD 种子下载 ...
- box-shadow阴影覆盖问题
“商品库”栏下方阴影被覆盖,解决方法:给“商品库”盒子加“position:relative”
- mysql 案例 ~ insert插入慢的场景
一简介: insert出现慢日志中,应该怎么检测呢 二 理解:事务提交延迟,一般出现在写日志延迟的情况下,会有几种可能 场景: 1 RR模式下,insert等待gap lock锁导致的 ...
- P5270 无论怎样神树大人都会删库跑路
题目地址:P5270 无论怎样神树大人都会删库跑路 第一眼看上去是模拟,似乎是 \(O(n)\) 的 水题 信心满满的写完: #include <bits/stdc++.h> using ...