@@ -511,52 +511,52 @@ watch(count, function() {
511
511
<!-- rehype:className=wrap-text-->
512
512
513
513
### 监听多个值
514
- <!-- rehype:wrap-class=col-span-2-->
514
+ <!-- rehype:wrap-class=col-span-2 row-span-2 -->
515
515
516
516
``` html
517
517
<template >
518
- <h1 > {{ count1 }} </h1 >
519
- <h1 > {{ count2 }} </h1 >
520
- <button @click =" count1++" >count1</button >
521
- <button @click =" count2++" >count2</button >
518
+ <h1 > {{ count1 }} </h1 >
519
+ <h1 > {{ count2 }} </h1 >
520
+ <button @click =" count1++" >count1</button >
521
+ <button @click =" count2++" >count2</button >
522
522
</template >
523
523
524
524
<script setup >
525
- import { watch , ref } from ' vue' ;
526
-
527
- const count1 = ref (0 )
528
- const count2 = ref (0 )
529
-
530
- watch (
531
- // 监听的表达式或函数
532
- () => ({
533
- count1: count1 .value ,
534
- count2: count2 .value
535
- }),
536
- // 回调函数
537
- (newValue , oldValue ) => {
538
- // 在这里执行需要的逻辑
539
- console .log (' count1 或 count2 变化了:' , newValue);
540
- },
541
- // immediate: true 表示在初始渲染时立即执行一次回调函数,以便处理初始的状态。
542
- // deep: true 表示深度监听,即对 newValue 和 oldValue 进行深层比较,而不是简单的引用比较。
543
- { immediate: true , deep: true }
544
- );
525
+ import { watch , ref } from ' vue' ;
526
+
527
+ const count1 = ref (0 )
528
+ const count2 = ref (0 )
529
+
530
+ watch (
531
+ // 监听的表达式或函数
532
+ () => ({
533
+ count1: count1 .value ,
534
+ count2: count2 .value
535
+ }),
536
+ // 回调函数
537
+ (newValue , oldValue ) => {
538
+ // 在这里执行需要的逻辑
539
+ console .log (' count1 或 count2 变化了:' , newValue);
540
+ },
541
+ // immediate: true 表示在初始渲染时立即执行一次回调函数,以便处理初始的状态。
542
+ // deep: true 表示深度监听,即对 newValue 和 oldValue 进行深层比较,而不是简单的引用比较。
543
+ { immediate: true , deep: true }
544
+ );
545
545
</script >
546
546
547
547
<style scoped >
548
548
</style >
549
549
```
550
550
551
551
### 计算状态
552
- <!-- rehype:wrap-class=col-span-2-->
553
552
554
553
``` html
555
554
<script setup >
556
555
import { ref , computed } from ' vue' ;
557
556
558
557
const text = ref (' ' )
559
- // computed 的回调函数里,会根据已有并用到的状态计算出新的状态
558
+ // computed 的回调函数里
559
+ // 会根据已有并用到的状态计算出新的状态
560
560
const capital = computed (function (){
561
561
return text .value .toUpperCase ();
562
562
})
0 commit comments