仅仅为了方便学习记录信息,未有其他用途。(采摘)
与 2.x 版本生命周期相对应的组合式 API
- beforeCreate -> 使用 setup()
- created -> 使用 setup()
- beforeMount -> onBeforeMount
- mounted -> onMounted
- beforeUpdate -> onBeforeUpdate
- updated -> onUpdated
- beforeDestroy -> onBeforeUnmount
- destroyed -> onUnmounted
- errorCaptured -> onErrorCaptured
- 新增:调试钩子函数:
- onRenderTracked
- onRenderTriggered
export default {
//v2
beforeCreate () {
console.log('beforeCreate()')
},
created () {
console.log('created')
},
beforeMount () {
console.log('beforeMount')
},
mounted () {
console.log('mounted')
},
//v3
setup() {
onBeforeMount(() => {
console.log('--onBeforeMount')
})
onMounted(() => {
console.log('--onMounted')
})
onRenderTriggered(e) {
debugger
// 检查哪个依赖性导致组件重新渲染
},
return {}
}
}
Composition API(手写)<===========================>配置vue.config