<template>
<div>
<h3>name:{{ person.name }}</h3>
<h3>age:{{ person.age }}</h3>
<button @click="add2">涨年龄</button>
</div>
</template>
<script>
import { reactive, watchEffect } from "vue";
export default {
setup() {
let person = reactive({
name: "李四",
age: 16,
});
function add2() {
person.age++;
}
//监听所有定义的响应式数据,
watchEffect(() => {
console.log(person.age);
});
return {
person,
add2,
};
},
};
</script>
Vue3.0 watchEffect
最新推荐文章于 2024-09-15 16:33:50 发布