@@ -511,52 +511,52 @@ watch(count, function() {
511511<!-- rehype:className=wrap-text-->
512512
513513### 监听多个值
514- <!-- rehype:wrap-class=col-span-2-->
514+ <!-- rehype:wrap-class=col-span-2 row-span-2 -->
515515
516516``` html
517517<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 >
522522</template >
523523
524524<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+ );
545545 </script >
546546
547547<style scoped >
548548 </style >
549549```
550550
551551### 计算状态
552- <!-- rehype:wrap-class=col-span-2-->
553552
554553``` html
555554<script setup >
556555import { ref , computed } from ' vue' ;
557556
558557const text = ref (' ' )
559- // computed 的回调函数里,会根据已有并用到的状态计算出新的状态
558+ // computed 的回调函数里
559+ // 会根据已有并用到的状态计算出新的状态
560560const capital = computed (function (){
561561 return text .value .toUpperCase ();
562562})
0 commit comments