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

40 lines
753 B

  1. <template>
  2. <div class="person">
  3. <h2>姓名{{ person.name }}</h2>
  4. <h2>年龄{{ person.age }}</h2>
  5. <button @click="changeName">修改名字</button>
  6. <button @click="changeAge">修改年龄</button>
  7. </div>
  8. </template>
  9. <script lang="ts" setup name="Person2">
  10. import {reactive, toRefs,toRef} from 'vue'
  11. //数据
  12. let person = reactive({
  13. name:'张三',
  14. age:18
  15. })
  16. let {name,age} = toRefs(person)
  17. let nl = toRef(person , 'age')
  18. console.log(nl.value)
  19. function changeName(){
  20. name.value += '~'
  21. }
  22. function changeAge(){
  23. age.value += 1
  24. }
  25. </script>
  26. <style scoped>
  27. .person{
  28. background-color: aquamarine;
  29. box-shadow: 0 0 10px;
  30. border-radius: 10px;
  31. padding: 20px;
  32. }
  33. </style>