眾所周知,vue2有生命週期,而vue3也有
而vue2的created和beforecreated在vue3中都由setup替代了
<script setup lang="ts"> import { onBeforeMount, onMounted, onBeforeUpdate, onUpdated,onBeforeUnmount,onUnmounted } from 'vue' console.log('建立生命週期') onBeforeMount(() => { console.log('掛載前') }) onMounted(() => { console.log('掛載完畢') }) onBeforeUpdate(() => { console.log('更新前') }) onUpdated(() => { console.log('更新完畢') }) onBeforeUnmount(() => { console.log('解除安裝前') }) onUnmounted(() => { console.log('解除安裝完畢') }) </script> <template> <div> </div> </template> <style scoped></style>