提交学习笔记专用
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.

32 lines
766 B

  1. <template>
  2. <div class="person">
  3. <h1>情况一监视ref定义的基本类型数据</h1>
  4. <h2>当前求和为{{sum}}</h2>
  5. <button @click="changeSum">点我sum+1</button>
  6. </div>
  7. </template>
  8. <script lang="ts" setup name="Person">
  9. import {ref,watch} from 'vue'
  10. // 数据
  11. let sum = ref(0)
  12. // 方法
  13. function changeSum(){
  14. sum.value += 1
  15. }
  16. // 监视,情况一:监视【ref】定义的【基本类型】数据
  17. const stopWatch = watch(sum,(newValue,oldValue)=>{
  18. console.log('sum变化了',newValue,oldValue)
  19. if(newValue >= 10){
  20. stopWatch()
  21. }
  22. })
  23. </script>
  24. <style scoped>
  25. .person{
  26. background-color: aquamarine;
  27. box-shadow: 0 0 10px;
  28. border-radius: 10px;
  29. padding: 20px;
  30. }
  31. </style>