|
@@ -0,0 +1,65 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <h1>shallowRef&&shallowReactive</h1>
|
|
|
+ <!-- <h3>Ref:{{ sum }}</h3>
|
|
|
+ <h3>shallowRef:{{ sum1 }}</h3> -->
|
|
|
+ <h3>Ref:{{ car.brand }}--{{ car.color }}--{{ car.options.a }}</h3>
|
|
|
+ <h3>shallowRef:{{ car1.brand }}--{{ car1.color }}--{{ car1.options.b }}</h3>
|
|
|
+ <button @click="changePart1">修改ref</button>
|
|
|
+ <button @click="changePart2">修改shallowRef</button>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup>
|
|
|
+import { ref, reactive, shallowRef,shallowReactive} from 'vue'
|
|
|
+let sum = ref(10);
|
|
|
+console.log(sum.value,'1');
|
|
|
+let sum1 = shallowRef(20);
|
|
|
+console.log(sum1.value,'2');
|
|
|
+function changePart1() {
|
|
|
+ // // sum.value = 20;
|
|
|
+ // car.brand = '奔驰1';
|
|
|
+ // car.color = 'white'
|
|
|
+ car.options.a = '10'
|
|
|
+ // car =
|
|
|
+ // Object.assign(car,{
|
|
|
+ // brand:"哈哈",
|
|
|
+ // color:'hh'
|
|
|
+ // })
|
|
|
+}
|
|
|
+function changePart2() {
|
|
|
+ // sum1.value = 30;
|
|
|
+ // car1.brand = '劳斯莱斯1';
|
|
|
+ // car1.color = 'black'
|
|
|
+ car1.options.b = '100'
|
|
|
+
|
|
|
+ // car1.value = {
|
|
|
+ // brand:"哈哈",
|
|
|
+ // color:'hh'
|
|
|
+ // }
|
|
|
+ // Object.assign(car1,{
|
|
|
+ // brand:"哈哈",
|
|
|
+ // color:'hh'
|
|
|
+ // })
|
|
|
+}
|
|
|
+let car = reactive({
|
|
|
+ brand:"奔驰",
|
|
|
+ color: 'black',
|
|
|
+ options:{
|
|
|
+ a:1,
|
|
|
+
|
|
|
+ }
|
|
|
+})
|
|
|
+let car1 = shallowReactive({
|
|
|
+ brand:"劳斯莱斯",
|
|
|
+ color: 'white',
|
|
|
+ options:{
|
|
|
+ b:2,
|
|
|
+
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+</script>
|
|
|
+<style lang='scss' scoped>
|
|
|
+
|
|
|
+</style>
|