Try   HackMD
tags: Vue

【Vue】生命週期

註冊與使用

<script setup> import { onMounted } from 'vue' onMounted(() => { console.log(`the component is now mounted.`) }) </script>
  • 必須是同步的
setTimeout(() => { onMounted(() => { //this won't work. }) }, 100)
  • 可以在 setup 外使用
  • 在 composition api 中 created() 是 setup()

所有的 api: https://vuejs.org/api/composition-api-lifecycle.html