Demo17.vue 615 B

123456789101112131415161718192021222324252627282930313233
  1. <template>
  2. <div>
  3. <h1>readonly</h1>
  4. <h2>Ref:{{ bb.name }}--{{ bb.age }}--{{ bb.x.a }}</h2>
  5. <button @click="handleChange">修改</button>
  6. </div>
  7. </template>
  8. <script lang="ts" setup>
  9. import { ref, reactive, shallowReadonly } from "vue";
  10. let aa = ref({
  11. name: "图图",
  12. age: 3,
  13. x: {
  14. a: 1,
  15. },
  16. });
  17. let bb = shallowReadonly(aa);
  18. function handleChange() {
  19. // bb.name = "孙悟空";
  20. // // aa.age = 30;
  21. // bb.value.x.a = 99;
  22. // bb.value = {
  23. // name: "猪八戒",
  24. // age: 4,
  25. // x: { a: 88 },
  26. // };
  27. // Object.assign(bb, aa1);
  28. }
  29. </script>
  30. <style lang="scss" scoped>
  31. </style>