vue3 生命週期06

文采呱呱發表於2024-03-13

眾所周知,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>