| 🔥生命周期 | 执行时机 |
|---|---|
| 🔥beforeCreate | 在组件实例被创建之初、组件的属性⽣效之前被调用 |
| 🔥created | 在组件实例已创建完毕。此时属性也已绑定,但真实DOM还未⽣成,$el 还不可⽤ |
| 🔥beforeMount | 在组件挂载开始之前被调⽤。相关的 render 函数⾸次被调⽤ |
| 🔥mounted | 在 el 被新建的 vm.$el 替换并挂载到实例上之后被调用 |
| 🔥beforeUpdate | 在组件数据更新之前调⽤。发⽣在虚拟 DOM 打补丁之前 |
| 🔥 update | 在组件数据更新之后被调用 |
| 🔥 activited | 在组件被激活时调⽤(使用了 的情况下) |
| 🔥 deactivated | 在组件被销毁时调⽤(使用了 的情况下) |
| 🔥 beforeDestory | 在组件销毁前调⽤ |
| 🔥 destoryed | 在组件销毁后调⽤ |
代码详情
class Vue{ constructor( options ){ options.beforeCreate.call(this) this.$data = options.data; options.created.call(this) options.beforeMount.call(this) this.$el = document.querySelector(options.el); options.mounted.call(this) } }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
new Vue({ el:"#app", data : { str:'123' }, beforeCreate(){ console.log('beforeCreate',this.$el , this.$data) }, created(){ console.log('created',this.$el , this.$data) }, beforeMount(){ console.log('beforeMount',this.$el , this.$data) }, mounted(){ console.log('mounted',this.$el , this.$data) }, })
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
beforeCreatecreated在这里插入代码片beforeMountmounted
activateddeactivated
beforeCreatecreatedbeforeMountmountedactivated
activated
🔥挂载阶段
beforeCreatecreatedbeforeMount
beforeCreatecreatedbeforeMountmountedmounted🔥更新阶段
beforeUpdate
eforeUpdateupdatedupdated🔥销毁阶段
beforeDestroy
beforeDestroydestroyeddestroyed