| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <template>
- <div>
- <h1>shallowRef与shallowReactive</h1>
- <h2>Ref:{{ cc.name }}--{{ cc.age }}--{{ cc.x.a }}</h2>
- <h2>shallowRef:{{ dd.name }}--{{ dd.age }}--{{ dd.x.a }}</h2>
- <button @click="handleChange">修改</button>
- </div>
- </template>
- <script lang="ts" setup>
- import { ref, reactive, shallowRef, shallowReactive } from "vue";
- let aa = ref(1);
- let bb = shallowRef(33);
- let cc = reactive({
- name: "图图",
- age: 3,
- x: {
- a: 1,
- },
- });
- let dd = shallowReactive({
- name: "小明",
- age: 13,
- x: {
- a: 3,
- },
- });
- const handleChange = () => {
- Object.assign(dd, {
- name: 1,
- age: 2,
- x: { a: 3 },
- });
- // cc.name = "孙悟空";
- // dd.value.x.a = 11;
- // dd.value = {
- // name: "猪八戒",
- // age: 4,
- // x: { a: 99 },
- // };
- // dd.value.name = "12";
- // aa.value++;
- // bb.value++;
- };
- </script>
- <style lang="scss" scoped>
- </style>
|