022:尚硅谷watchEffect响应式监控学习示例
This commit is contained in:
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
|
||||||
import { reactive, watch } from 'vue'
|
import { reactive, watchEffect } from 'vue'
|
||||||
let person = reactive({
|
let person = reactive({
|
||||||
name: 'John',
|
name: 'John',
|
||||||
age: 25,
|
age: 25,
|
||||||
@@ -52,9 +52,14 @@
|
|||||||
// watch(()=>person.age, (newValue, oldValue) => {
|
// watch(()=>person.age, (newValue, oldValue) => {
|
||||||
// console.log('person changed:', newValue, oldValue)
|
// console.log('person changed:', newValue, oldValue)
|
||||||
// })
|
// })
|
||||||
watch([person.car,()=>person.name], (newValue, oldValue) => {
|
// watch([person.car,()=>person.name], (newValue, oldValue) => {
|
||||||
console.log('汽车变化了:', newValue, oldValue)
|
// console.log('汽车变化了:', newValue, oldValue)
|
||||||
},{deep:true})
|
// },{deep:true})
|
||||||
|
watchEffect(()=>{
|
||||||
|
if(person.age>200){
|
||||||
|
console.log('年龄大于200')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user