shallowReactive.vue 882 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <template>
  2. <div>
  3. <h1>shallowReactive</h1>
  4. <h3>reactive:{{ obj.name }} -- {{ obj.age }}</h3>
  5. <h3>shallowReactive:{{ obj1.name }} -- {{ obj1.age }}--{{ obj1.address.city }}--{{ obj1.address.area }}</h3>
  6. <button @click="changeObj">修改</button>
  7. </div>
  8. </template>
  9. <script lang="ts" setup>
  10. import {ref,reactive,shallowReactive} from "vue"
  11. let obj = reactive({
  12. name: '孙悟空',
  13. age: 18
  14. })
  15. let obj1 = shallowReactive({
  16. name: '唐僧',
  17. age: 20,
  18. address:{
  19. city: '北京',
  20. area: '朝阳'
  21. }
  22. })
  23. function changeObj() {
  24. // Object.assign(obj1,{
  25. // name: '猪八戒',
  26. // age: 28
  27. // })
  28. // obj1.name = '猪八戒'
  29. // obj1.address = {
  30. // city: '上海',
  31. // area: '浦东'
  32. // }
  33. obj1.address.city = '上海'
  34. }
  35. console.log(obj,obj1);
  36. </script>
  37. <style lang="scss" scoped>
  38. </style>