说些题外话,引出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生命周期的更多相关文章

  1. vue生命周期的理解

    我从官网上下载了一张vue生命周期的图,接下来实际分析一波vue到底执行了什么东西. 1.我们在使用vue时必不可少的操作就是 var vm = new Vue({}),这样我们就创建了一个vue的实 ...

  2. 详解vue生命周期

    vue生命周期 @(vue)[生命周期] 前言 在使用vue一个多礼拜后,感觉现在还停留在初级阶段,虽然知道怎么和后端做数据交互,但是对于mounted这个挂载还不是很清楚的.放大之,对vue的生命周 ...

  3. Vue生命周期,面试常见问题

    一.对于MVVM的理解? MVVM 是 Model-View-ViewModel 的缩写.Model代表数据模型,也可以在Model中定义数据修改和操作的业务逻辑.View 代表UI 组件,它负责将数 ...

  4. 【Vue笔记】-- 详解vue生命周期

    针对于Vue的生命周期进行详细的说明,方面加深对各个方法的引用. 引言: 前几天重新回顾vue官网时,看到vue的生命周期,想着自己用vue开发了快一年了,就总结总结vue知识,再次加深自己对vue的 ...

  5. 面试题之(vue生命周期)

    在面试的时候,vue生命周期被考察的很频繁. 什么是vue生命周期呢? Vue实例有一个完整的生命周期,也就是从开始创建.初始化数据.编译模板.挂载Dom.渲染→更新→渲染.卸载等一系列过程,我们称这 ...

  6. vue生命周期图示中英文版Vue实例生命周期钩子

    vue生命周期图示中英文版Vue实例生命周期钩子知乎上近日有人发起了一个 “react 是不是比 vue 牛皮,为什么?” 的问题,Vue.js 作者尤雨溪12月4日正面回应了该问题.以下是尤雨溪回复 ...

  7. vue生命周期钩子

    转载自:https://segmentfault.com/a/1190000008010666?utm_source=tag-newest https://segmentfault.com/a/119 ...

  8. 理解mpvue的生命周期

    mpvue是美团基于vue开发的一个开发小程序的框架,从而以vue的语法来开发小程序.在生命周期上,mpvue同时支持了vue的生命周期和小程序的生命周期,这可能让新上手的同学费解.这篇文章就来讲讲m ...

  9. VUE自定义指令生命周期,VUE生命周期

    一.自定义指令的生命周期 自定义指令有五个生命周期(也叫钩子函数),分别是 bind,inserted,update,componentUpdated,unbind bind:只调用一次,指令第一次绑 ...

随机推荐

  1. shop++之language

    shop++商城改造此次感悟最深的就是封装.有些东西要整明白就得花点时间. 代码中经常用到这种,我照葫芦画瓢竟然没有用. 天啦,竟然是自己没有定义,还以为是什么高级自动的玩意呢? 文件结构如下: 后面 ...

  2. Part-Seven

    1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12.

  3. python模块之自定义模块

    模块概述 到此之前,我们都是在一个py文件里操作,接下来,我们学习模块的内容,可以从其他文件引入内容(如函数等) 1. 什么是模块 一个py文件就是一个模块,模块是一些相似功能的集合体 2. 为什么要 ...

  4. Vue.js入门系列教程(三)

    序言

  5. Java8新特性_stream API 练习

    交易员类 public class Trader { private String name; private String city; public Trader() { } public Trad ...

  6. linux关闭防火墙及开放端口

    1) 重启后生效 开启: chkconfig iptables on 关闭: chkconfig iptables off 2) 即时生效,重启后失效 开启: service iptables sta ...

  7. 实时监听 input值的变化

    重点:$('#xx').bind('input propertychange', function() {} 举例子: html: <div ><span id="numb ...

  8. [C++]PAT乙级1012.数字分类 (20/20)

    /* 1012. 数字分类 (20) 给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字: A1 = 能被5整除的数字中所有偶数的和: A2 = 将被5除后余1的数字按给出顺序进行交错求和, ...

  9. 第21月第4天 leetcode codinginterview c++

    1.leetcode Implement strStr(). Returns the index of the first occurrence of needle in haystack, or - ...

  10. MySql数据库学习笔记(2)

    DELETE 语法:delete from 表名 [where condition] delete from grade; TRUNCATE 用于完全清空表数据,但表结构.索引.约束不变: 语法: t ...