|
@@ -0,0 +1,40 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <h2>watch2.0=>ref引用数据类型</h2>
|
|
|
+ <h3>我在{{ obj.city }},现在是{{ obj.month }}</h3>
|
|
|
+ <button @click="changeCity">修改城市</button>
|
|
|
+ <button @click="changeMonth">修改月份</button>
|
|
|
+ <button @click="changeMsg">修改信息</button>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script lang="ts" setup>
|
|
|
+import {ref,watch} from 'vue';
|
|
|
+let obj = ref({
|
|
|
+ city:"哈尔滨",
|
|
|
+ month:"五月"
|
|
|
+})
|
|
|
+function changeCity(){
|
|
|
+ obj.value.city = '北京'
|
|
|
+}
|
|
|
+function changeMonth(){
|
|
|
+ obj.value.month = '六月'
|
|
|
+
|
|
|
+}
|
|
|
+function changeMsg(){
|
|
|
+ obj.value = {
|
|
|
+ city:"天津",
|
|
|
+ month:"七月"
|
|
|
+ }
|
|
|
+}
|
|
|
+watch(obj,(newValue,oldValue)=>{
|
|
|
+ console.log(newValue,oldValue)
|
|
|
+},{
|
|
|
+ deep: true,
|
|
|
+ immediate: true
|
|
|
+})
|
|
|
+
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss" scoped>
|
|
|
+</style>
|