022:尚硅谷watchEffect响应式监控学习示例

This commit is contained in:
heiye111
2025-10-02 16:00:23 +08:00
parent 20907407c7
commit a62bda33c8

View File

@@ -18,7 +18,7 @@
<script setup lang="ts">
import { reactive, watch } from 'vue'
import { reactive, watchEffect } from 'vue'
let person = reactive({
name: 'John',
age: 25,
@@ -52,9 +52,14 @@
// watch(()=>person.age, (newValue, oldValue) => {
// console.log('person changed:', newValue, oldValue)
// })
watch([person.car,()=>person.name], (newValue, oldValue) => {
console.log('汽车变化了:', newValue, oldValue)
},{deep:true})
// watch([person.car,()=>person.name], (newValue, oldValue) => {
// console.log('汽车变化了:', newValue, oldValue)
// },{deep:true})
watchEffect(()=>{
if(person.age>200){
console.log('年龄大于200')
}
})
</script>