博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
vue生命周期
阅读量:7023 次
发布时间:2019-06-28

本文共 3093 字,大约阅读时间需要 10 分钟。

vue的学习首要任务是掌握生命周期

beforeCreate--组件刚刚创建,组件属性就算之前,data属性等
created---组件刚刚创建完成,属性已经绑定,DOM还未生成,$el属性还不存在
beforeMount--模板编译挂载之前
mounted --- 模板编译挂载之后
beforeUpdate --- 组件更新之前
updated --- 组件更新之后
activated---组件被激活时调用
deactivated -- 组件被移除时调用
beforeDistory -- 组件销毁前调用
distoryed -- 组件销毁后调用
对于执行顺序和什么时候执行,基本有个了解了。下面我们将结合代码去看看钩子函数的执行

var app = new Vue({  el: '#app',  data: {      message : "hello world"   },   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)      },    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); //已被初始化    },    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); //已被初始化      },    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); //已被初始化     },    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);     },    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);     },    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)    }})复制代码

转载地址:http://anvxl.baihongyu.com/

你可能感兴趣的文章
springmvc hello-servlet.xml配置文件
查看>>
kindeditor + syntaxhighlighter 使文章内的插入代码高亮显示
查看>>
angular2 学习二 [property] - 绑定属性
查看>>
iostat 实例分析
查看>>
php学习日记
查看>>
Qt新建项目
查看>>
虚拟机的克隆并更改主机名
查看>>
分享一波Android面试题
查看>>
python入门系列:文件操作
查看>>
适合练习的10个Python项目,每个项目都不到500行代码
查看>>
iOS宏定义的使用与规范
查看>>
Cisco ASA 应用NAT
查看>>
微信环境中不支持APP(APK)文件下载的解决方案---使用augpush实现跳转
查看>>
Python进阶之路 3.4.4 比较运算符
查看>>
数据库系统学习二
查看>>
extmail一个正常收发邮件log(内网测试)
查看>>
深入探索spring技术内幕(五): 剖析spring AOP工作原理
查看>>
利用内容提供者来操作联系人数据库
查看>>
UNIX网络编程书中源代码测试环境搭建 (centos中取时间问题)
查看>>
解决IP地址冲突的问题
查看>>