022:尚硅谷watchEffect响应式监控学习示例
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user