Vue生命周期函数的应用
- <!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>
Vue生命周期函数的应用的更多相关文章
- Vue生命周期函数详解
vue实例的生命周期 1 什么是生命周期(每个实例的一辈子) 概念:每一个Vue实例创建.运行.销毁的过程,就是生命周期:在实例的生命周期中,总是伴随着各种事件,这些事件就是生命周期函数: 生命周期: ...
- Vue生命周期函数
生命周期函数: 组件挂载,以及组件更新,组建销毁的时候出发的一系列方法. beforeCreate:实例创建之前 created:实例创建完成 beforeMount:模板编译之前 mounted:模 ...
- Vue学习之路第二十篇:Vue生命周期函数-组件创建期间的4个钩子函数
1.每个 Vue 实例在被创建时都要经过一系列的初始化过程——例如,需要设置数据监听.编译模板.将实例挂载到 DOM 并在数据变化时更新 DOM 等.同时在这个过程中也会运行一些叫做生命周期钩子的函数 ...
- vue生命周期函数2
转载:http://blog.csdn.net/qq_15766181/article/details/73549933 钩子就好像是把人的出生到死亡分成一个个阶段,你肯定是在出生阶段起名字,而不会在 ...
- vue 生命周期函数详解
beforeCreate( 创建前 ) 在实例初始化之后,数据观测和事件配置之前被调用,此时组件的选项对象还未创建,el 和 data 并未初始化,因此无法访问methods, data, compu ...
- Vue.js小案例、生命周期函数及axios的使用
一.调色框小案例: 随着三个滑动框的变化,颜色框的颜色随之改变 1.1.实例代码 <!DOCTYPE html> <html lang="en" xmlns:v- ...
- Vue之生命周期函数和钩子函数详解
在学习vue几天后,感觉现在还停留在初级阶段,虽然知道怎么和后端做数据交互,但是对对vue的生命周期不甚了解.只知道简单的使用,而不知道为什么,这对后面的踩坑是相当不利的.因为我们有时候会在几个钩子函 ...
- vue实例的生命周期函数
Vue的生命周期函数通常分为以下三类: ①实例创建时的生命周期函数:②实例执行时的生命周期的函数:③实例销毁时的生命周期的函数. 代码与注释详解: <!DOCTYPE html> < ...
- vue(4)—— vue的过滤器,监听属性,生命周期函数,获取DOM元素
过滤器 vue允许自定义过滤器,我个人认为,过滤器有两种,一种是对数据的清洗过滤,一种是对数据切换的动画过滤 数据切换的动画过滤 这里还是利用前面的动态组件的例子: 这里由于没办法展示动画效果,代码如 ...
随机推荐
- 【ACM-ICPC 2018 南京赛区网络预赛 A】An Olympian Math Problem
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 估计试几个就会发现答案总是n-1吧. 队友给的证明 [代码] #include <bits/stdc++.h> #def ...
- [React Router] Prevent Navigation with the React Router Prompt Component
In this lesson we'll show how to setup the Prompt component from React Router. We'll prompt with a s ...
- Android自己定义对话框实现QQ退出界面
效果 首先看下qq的效果图,点击菜单button后点退出就会出现如图的对话框. 从上图能够看出,该对话框有一个圆角,以及标题,提示信息,两个button,button颜色是白色,button点击后背景 ...
- 【Android 应用开发】 ActionBar 样式具体解释 -- 样式 主题 简单介绍 Actionbar 的 icon logo 标题 菜单样式改动
作者 : 万境绝尘 (octopus_truth@163.com) 转载请著名出处 : http://blog.csdn.net/shulianghan/article/details/3926916 ...
- 9patch生成图片
private Bitmap get_ninepatch(int id,int x, int y, Context context){ // id is a resource id for a val ...
- SQL语句之transaction
http://blog.csdn.net/xbc1213/article/details/50169935 案例: begin tran --定义一个存储错误新的变量 执行一条语句 set @sumE ...
- mongo服务器异常
1.Detected unclean shutdown - /data/db/mongod.lock is not empty. 前几天把研究用的虚拟机直接关了回家过年,今天启动发现启动不了,报了个u ...
- 当安装了ubuntu操作系统怎么也调用不出中文输入法时,可以用以下方式尝试解决。
卸载 fcitx sudo apt-get remove fcitx 重启 sudo reboot 重新安装 fcitxsudo apt-get isntall fcitx 安装拼音输入法sudo a ...
- Ubuntu 16.04或14.04里下安装搜狗输入法(图文详解)(全网最简单)
不多说,直接上干货! 其实啊,很简单 分三步走 1.添加fcitx的键盘输入法系统,因为sogou是基于fcitx的,而系统默认的是iBus: 2.安装sogou输入法: 3.设置系统参数及一些注意点 ...
- Spark编程模型几大要素
不多说,直接上干货! Spark编程模型几大要素 Driver Program 输入-Transformation-Action 缓存 共享变量