|
@@ -0,0 +1,35 @@
|
|
|
|
|
+<template>
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <h1>Demo11</h1>
|
|
|
|
|
+ <h2>{{ name }}--{{ age }}</h2>
|
|
|
|
|
+ <button @click="changeName">修改名字</button>
|
|
|
|
|
+ <button @click="changeAge">修改年龄</button>
|
|
|
|
|
+ <button @click="changePerson">修改整个人</button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+</template>
|
|
|
|
|
+
|
|
|
|
|
+<script lang="ts" setup>
|
|
|
|
|
+import { ref, reactive, watch, watchEffect } from "vue";
|
|
|
|
|
+let name = ref("图图");
|
|
|
|
|
+let age = ref(3);
|
|
|
|
|
+function changeName() {
|
|
|
|
|
+ name.value = "孙悟空";
|
|
|
|
|
+}
|
|
|
|
|
+function changePerson() {
|
|
|
|
|
+ name.value = "猪八戒";
|
|
|
|
|
+ age.value = 4;
|
|
|
|
|
+}
|
|
|
|
|
+function changeAge() {
|
|
|
|
|
+ age.value = 30;
|
|
|
|
|
+}
|
|
|
|
|
+// watch([name, age], (newValue, oldValue) => {
|
|
|
|
|
+// console.log("新值", newValue);
|
|
|
|
|
+// console.log("旧值", oldValue);
|
|
|
|
|
+// });
|
|
|
|
|
+watchEffect(() => {
|
|
|
|
|
+ console.log("watchEffect", name.value, age.value);
|
|
|
|
|
+});
|
|
|
|
|
+</script>
|
|
|
|
|
+
|
|
|
|
|
+<style lang="scss" scoped>
|
|
|
|
|
+</style>
|