1、选项模式
示例
createApp({
created(){}
mounted(){}}
})
2、组合模式
示例1
<script setup>
Vue.onCreated(()=>{})
Vue.onMounted(()=>{})
</script>
示例2
<script >
export default{
created(){}
mounted(){}}
}
</script>
3、在组合模式中,周期勾子中不能使用this,如要获得当前的Vue组件对象,可以使用getCurrentInstance()方法
示例
Vue.onMounted((v)=>{
console.log(Vue.getCurrentInstance());
})