爱分享的代码君

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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());
})
posted on 2024-09-27 14:35  爱分享的代码君  阅读(3)  评论(0)    收藏  举报