一、选项式API
选项式API可以单独作为选项使用
- beforeCreate
组件实例初始化之前
- created
组件实例初始化之后。所有状态选项状态完成,响应数据、计算属性、方法、监听器
- beforeMount
组件被挂载之前。完成所有响应状态,还没有创建dom节点
- mounted
组件被挂载之后。(1)所有子组件被挂载(2)DOM树创建并插入到父容器
- beforeUpdate
响应式状态变更而更新DOM树之前
- updated
响应式状态变更而更新DOM树之后
- beforeUnmount
组件实例被卸载之前
- unMounted
组件实例被卸载之后
二、组合式API
组合式API,通过import按需引入后,在setup中通过函数使用
- setup()
相当于beforeCreate和created
- onBeforeMount
相对于beforeMount
- onMounted
相对于mounted
- onBeforeUpdate
相对于beforeUpdate
- onUpdated
相对于updated
- onBeforeUnmount
相对于beforeUnmount
- onUnMounted
相对于unMounted