bailing 2 weeks ago
parent
commit
4974e28d6d

+ 6 - 1
15.vue3/vue_project1/src/App.vue

@@ -9,8 +9,11 @@
     <Demo7 />
     <Demo8/>
     <Demo9/>
-    <Demo10/> -->
+    <Demo10/>
     <Demo11/>
+    <Demo12/>
+     -->
+    <Demo13/>
   </div>
 </template>
 
@@ -26,6 +29,8 @@ import Demo8 from "./components/Demo8.vue";
 import Demo9 from "./components/Demo9.vue";
 import Demo10 from "./components/Demo10.vue";
 import Demo11 from "./components/Demo11.vue";
+import Demo12 from "./components/Demo12.vue";
+import Demo13 from "./components/Demo13.vue";
 </script>
 <style></style>
 

+ 58 - 0
15.vue3/vue_project1/src/components/Demo12.vue

@@ -0,0 +1,58 @@
+<template>
+  <div>
+    <h2>watch5.0=>reactive引用数据类型</h2>
+    <h3>我在{{ obj.city }},现在是{{ obj.month }}</h3>
+    <p>今天是一个{{ obj.weather.sun }},明天是一个{{ obj.weather.rain }}</p>
+    <button @click="changeCity">修改城市</button>
+    <button @click="changeMonth">修改月份</button>
+    <button @click="changeMsg">修改信息</button>
+    <button @click="changePart1">修改第一天</button>
+    <button @click="changePart2">修改第二天</button>
+    <button @click="changeWeather">修改天气</button>
+  </div>
+</template>
+
+<script lang="ts" setup>
+import { reactive, watch } from "vue";
+let obj = reactive({
+  city: "哈尔滨",
+  month: "五月",
+  weather:{
+    sun:"晴天",
+    rain:"雨天"
+  }
+});
+function changeCity() {
+  obj.city = "天津";
+}
+function changeMonth() {
+  obj.month = "六月";
+}
+function changePart1() {
+  obj.weather.sun = '第一个'
+}
+function changePart2() {
+
+  obj.weather.rain = '第二个'
+}
+function changeWeather() {
+  obj.weather = {
+    sun:"修改后1",
+    rain:"修改后2"
+  }
+}
+function changeMsg() {
+  Object.assign(obj, { city: "北京", month: "七月" });
+}
+watch([()=>obj.city,()=>obj.weather],(newValue, oldValue) => {
+    console.log(newValue, oldValue);
+  },
+  {
+    deep: true,
+    immediate: true
+  }
+);
+</script>
+
+<style lang="scss" scoped>
+</style>

+ 12 - 0
15.vue3/vue_project1/src/components/Demo13.vue

@@ -0,0 +1,12 @@
+<template>
+  <div>
+    <h1>生命周期</h1>
+  </div>
+</template>
+
+<script lang="ts" setup>
+
+</script>
+
+<style lang="scss" scoped>
+</style>