|
@@ -0,0 +1,29 @@
|
|
|
|
|
+<template>
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <h1>Demo10:watch监听rref/reactive引用数据类型中的某个属性</h1>
|
|
|
|
|
+ <h3>我有{{ flower.type }}花,是{{ flower.color }}</h3>
|
|
|
|
|
+ <button @click="changeFlowerColor">颜色</button>
|
|
|
|
|
+ <button @click="changeFlower">整体</button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+</template>
|
|
|
|
|
+
|
|
|
|
|
+<script lang="ts" setup>
|
|
|
|
|
+import {reactive,watch} from "vue"
|
|
|
|
|
+let flower = reactive({
|
|
|
|
|
+ color:"红色",
|
|
|
|
|
+ type:"牡丹"
|
|
|
|
|
+});
|
|
|
|
|
+function changeFlowerColor() {
|
|
|
|
|
+ flower.color = '粉色'
|
|
|
|
|
+}
|
|
|
|
|
+function changeFlower() {
|
|
|
|
|
+ Object.assign(flower, {type:"丁香花",color:"紫色"})
|
|
|
|
|
+}
|
|
|
|
|
+// 监听的是基本数据类型的值
|
|
|
|
|
+watch([() =>flower.type,()=>flower.color],(newValue,oldValue) => {
|
|
|
|
|
+ console.log(newValue,oldValue)
|
|
|
|
|
+})
|
|
|
|
|
+</script>
|
|
|
|
|
+
|
|
|
|
|
+<style lang="scss" scoped>
|
|
|
|
|
+</style>
|