watch的写法
// 1.watch一个ref对象
watch(result, () => {
console.log(result.value);
});
// 2.watch多个ref对象
watch([a, b], () => {
console.log(a.value);
console.log(b.value);
});
// 3.watch一个reactive的属性
const data: DataProps = reactive({
count: 0,
double: computed(() => {
return data.count * 2;
}),
increase: () => {
data.count++;
},
});
watch(()=> data.count, ()=> {
// do something
})
// watch方法接收2个参数, 分别是newValue和oldValue
// 如果是watch多个对象newValue和oldValue都是数组
watch(result, (newValue, oldValue) => {});
watchEffect的写法
watchEffect(() => {
console.log(nameObj.name)
})