diff --git a/20_脚手架/vue3_test/9.src_watch监视ref的数据的说明/App.vue b/20_脚手架/vue3_test/9.src_watch监视ref的数据的说明/App.vue
new file mode 100644
index 0000000..d709302
--- /dev/null
+++ b/20_脚手架/vue3_test/9.src_watch监视ref的数据的说明/App.vue
@@ -0,0 +1,13 @@
+
+
+
+
+
diff --git a/20_脚手架/vue3_test/9.src_watch监视ref的数据的说明/assets/logo.png b/20_脚手架/vue3_test/9.src_watch监视ref的数据的说明/assets/logo.png
new file mode 100644
index 0000000..f3d2503
Binary files /dev/null and b/20_脚手架/vue3_test/9.src_watch监视ref的数据的说明/assets/logo.png differ
diff --git a/20_脚手架/vue3_test/9.src_watch监视ref的数据的说明/components/demo.vue b/20_脚手架/vue3_test/9.src_watch监视ref的数据的说明/components/demo.vue
new file mode 100644
index 0000000..0e95fbd
--- /dev/null
+++ b/20_脚手架/vue3_test/9.src_watch监视ref的数据的说明/components/demo.vue
@@ -0,0 +1,67 @@
+
+ 当前求和为:{{ sum }}
+
+
+ 当前信息为:{{ msg }}
+
+
+ 姓名:{{ person.name }}
+ 年龄:{{ person.age }}
+ 薪资:{{ person.job.j1.salary }}
+
+
+
+
+
+
+
diff --git a/20_脚手架/vue3_test/9.src_watch监视ref的数据的说明/main.js b/20_脚手架/vue3_test/9.src_watch监视ref的数据的说明/main.js
new file mode 100644
index 0000000..8a90e5c
--- /dev/null
+++ b/20_脚手架/vue3_test/9.src_watch监视ref的数据的说明/main.js
@@ -0,0 +1,10 @@
+// 引入的不再是Vue构造函数, 引入的是一个名为createApp的工厂函数
+import { createApp } from 'vue'
+import App from './App.vue'
+
+// createApp(App).mount('#app')
+
+// 创建应用实例对象
+const app = createApp(App)
+console.log('@@@',app)
+app.mount('#app')
\ No newline at end of file
diff --git a/20_脚手架/vue3_test/src/components/demo.vue b/20_脚手架/vue3_test/src/components/demo.vue
index 795d60f..0e95fbd 100644
--- a/20_脚手架/vue3_test/src/components/demo.vue
+++ b/20_脚手架/vue3_test/src/components/demo.vue
@@ -37,7 +37,7 @@ export default {
setup() {
let sum = ref(0)
let msg = ref('你好呀')
- let person = reactive({
+ let person = ref({
name: '张三',
age: 18,
job: {
@@ -47,35 +47,15 @@ export default {
}
})
- // 情况一:监视ref的所有定义的一个响应式
- // watch(sum, (newValue, oldValue) => {
- // console.log('sum值变化了', newValue, oldValue)
- // }, {deep: true, immediate: true})
-
- // 情况二:监视ref的所有定义的多个个响应式
- watch([sum, msg], (newValue, oldValue) => {
- console.log('sum和msg的值变化了', newValue, oldValue)
- }, {immediate: true})
-
- // 情况三:监控reactive所定义的一个响应式数据中的全部属性,注意:此处无法正确的获取oldValue,强制开启deep
- // watch(person, (newValue, oldValue) => {
- // console.log('person对象的值变了', newValue, oldValue)
- // }, {deep: false})
-
- // 情况四:监控reactive所定义的一个响应式数据中的某个属性
- // watch(()=>person.age, (newValue,oldValue)=>{
- // console.log('person.age对象的值变了', newValue, oldValue)
+ // 方法一: ref的对象监视,通过value实现
+ // watch(person.value, (newValue, oldValue) => {
+ // console.log('person的值变了', newValue, oldValue)
// })
- // 情况五:监控reactive所定义的一个响应式数据中的某些属性
- watch([() => person.name, () => person.age], (newValue, oldValue) => {
- console.log('person.age和.name对象的值变了', newValue, oldValue)
- })
-
- // 特殊情况
- watch(() => person.job, (newValue, oldValue) => {
- console.log('person.job对象的值变了', newValue, oldValue)
- }, {deep: true})
+ // 方法二: ref的对象监视,通过deep实现
+ watch(person, (newValue, oldValue) => {
+ console.log('person的值变了', newValue, oldValue)
+ },{deep: true})
return {
sum,