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

65 lines
1.3 KiB

  1. <template>
  2. <div class="person">
  3. <h2>汽车信息一辆{{ car.brand }}价值{{ car.price }}</h2>
  4. <button @click="changePrice">修改汽车的价格</button>
  5. <br>
  6. <h2>游戏列表</h2>
  7. <ul>
  8. <li v-for="g in games" :key="g.id">{{ g.name }}</li>
  9. </ul>
  10. <button @click="changeFirstGame">修改第一个游戏的名字</button>
  11. <br>
  12. <h2>测试:{{ obj.a.b.c }}</h2>
  13. <button @click="changeObj">修改第一个游戏的名字</button>
  14. </div>
  15. </template>
  16. <script lang="ts" setup name="Person2">
  17. import {reactive, ref} from 'vue'
  18. //reative定义对象类型数据
  19. //数据
  20. let car = reactive({brand:'奔驰',price:100})
  21. let games = reactive([
  22. {id:'a01',name:"王者荣耀"},
  23. {id:'a02',name:"王者荣耀1"},
  24. {id:'a03',name:"王者荣耀2"}
  25. ])
  26. let obj = reactive({
  27. a:{
  28. b:{
  29. c:666
  30. }
  31. }
  32. })
  33. //方法
  34. function changePrice(){
  35. car.price +=10
  36. }
  37. function changeFirstGame(){
  38. if (games[0]) {
  39. games[0].name = '和平精英'
  40. }
  41. }
  42. function changeObj(){
  43. obj.a.b.c=999
  44. }
  45. </script>
  46. <style scoped>
  47. .person{
  48. background-color: aquamarine;
  49. box-shadow: 0 0 10px;
  50. border-radius: 10px;
  51. padding: 20px;
  52. }
  53. button{
  54. margin: 0 5px;
  55. }
  56. li{
  57. font-size: 20px;
  58. }
  59. </style>