提交学习笔记专用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
852 B

  1. <template>
  2. <div class="person">
  3. <h2>当前求和为:{{ sum }}</h2>
  4. <button @click="changeSum">点我sum+1</button>
  5. </div>
  6. </template>
  7. <!-- vue3写法 -->
  8. <script lang="ts" setup name="Person">
  9. import {
  10. ref,
  11. onBeforeMount,
  12. onMounted,
  13. onBeforeUpdate,
  14. onUpdated,
  15. onBeforeUnmount,
  16. onUnmounted
  17. } from 'vue'
  18. // 数据
  19. let sum = ref(0)
  20. // 方法
  21. function changeSum() {
  22. sum.value += 1
  23. }
  24. console.log('setup')
  25. // 生命周期钩子
  26. onBeforeMount(()=>{
  27. console.log('挂载之前')
  28. })
  29. onMounted(()=>{
  30. console.log('挂载完毕')
  31. })
  32. onBeforeUpdate(()=>{
  33. console.log('更新之前')
  34. })
  35. onUpdated(()=>{
  36. console.log('更新完毕')
  37. })
  38. onBeforeUnmount(()=>{
  39. console.log('卸载之前')
  40. })
  41. onUnmounted(()=>{
  42. console.log('卸载完毕')
  43. })
  44. </script>