036.Vue3入門,元件的生命週期

像一棵海草海草海草發表於2024-08-11

1、App.vue程式碼如下:

<template>
  <div>
    <h3>主頁面</h3>
    <button @click="change">改變</button>
  </div>
</template>

<script>
export default {
  beforeCreate() { console.log('beforeCreate') },
  created() { console.log('created') },
  beforeMount() { console.log('beforeMount') },
  beforeUpdate() { console.log('beforeUpdate') },
  beforeDestroy() { console.log('beforeDestroy') },
  mounted() { console.log('mounted') },
  updated() { console.log('updated') },
  destroyed() { console.log('destroyed') },
  methods: { change() { console.log('change') }
  }
}
</script>

2、效果如下:

相關文章