选项式API | 组合式API |
---|---|
beforeCreate/created | setup |
beforeMount | onbeforeMount |
mounted | onMounted |
beforeUpdate | onBeforeUpdate |
updated | onUpdated |
beforeUnmount | onBeforeUnmount |
unmounted | onUnmounted |
<script setup>
//生命周期的使用
//1.引入函数
import { onMounted } from 'vue';
//
onMounted(()=>{
console.log('组件挂载完毕mounted执行了');
})
</script>
生命周期函数是可以执行多次的,多次执行时传入的回调会在时机成熟时依次执行
onMounted(()=>{
console.log('mount1')
})
onMounted(()=>{
console.log('mount2')
)}