vue2生命周期
1.有哪些生命周期:
beforeCreate
created
beforeMount
mounted
beforeUpdate
updated
beforeDestroy
destroyed
2.一旦进入页面或组件会执行哪些生命周期:
beforeCreate
created
beforeMount
mounted
3.在哪个阶段有$el,$data:
从created开始有$data,从mounted开始有$el.
4.如果加入keep-alive会多两个生命周期:
activated
deactivated
5.如果加入keep-alive第一次进入组件会执行哪些生命周期,第二次或者第N次进入组件会执行哪些生命周期:
第一次:
beforeCreate
created
beforeMount
mounted
activated
第二次或第N次:
activated
6.如果要改版生命周期或者el和data出现的顺序要怎么做:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | <! DOCTYPE html> < html lang="en"> < head > < meta charset="UTF-8"> < meta http-equiv="X-UA-Compatible" content="IE=edge"> < meta name="viewport" content="width= , initial-scale=1.0"> < title >生命周期原理</ title > </ head > < script src="./vue.js"></ script > < body > < div id="App">这是vue</ div > </ body > < script > new vue({ el: '#App', data() { return { str: '124' } }, beforeCreate() { console.log(this)//这里this是这个VUE实例 console.log('beforeCreate', this.$data, this.$el) }, Created() { console.log('Created', this.$data, this.$el) }, beforeMount() { console.log('beforeMount', this.$data, this.$el) }, mounted() { console.log('mounted', this.$data, this.$el) }, }) </ script > </ html > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | class vue { constructor(options) { console.log(this)//这里this是这个VUE类 options.beforeCreate.bind(this)() this.$data = options.data options.Created.bind(this)() options.beforeMount.bind(this)() this.$el = document.querySelector(options.el) options.mounted.bind(this)() } } //模拟一个vue ,vue本质上就是一个class类,里面的方法其实是在构造函数里面执行的 |
本文作者:SadicZhou
本文链接:https://www.cnblogs.com/SadicZhou/p/16935910.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步