diff --git a/pages/composition-api/reactivity/watch-effect/watch-effect.uvue b/pages/composition-api/reactivity/watch-effect/watch-effect.uvue index 05e37b639387e994972d2407df3936c8a459b9a4..5e666bff5625431b903138189fb167ca87a5cfe3 100644 --- a/pages/composition-api/reactivity/watch-effect/watch-effect.uvue +++ b/pages/composition-api/reactivity/watch-effect/watch-effect.uvue @@ -50,9 +50,9 @@ const watchCountTrackNum = ref(0) const watchCountTriggerNum = ref(0) - const stopWatchCount = watchEffect((onCleanup: OnCleanup) => { + const stopWatchCount = watchEffect((onCleanup : OnCleanup) => { if (countRef.value !== null) { - watchCountRes.value = `count: ${count.value}, count ref text (flush sync): ${(countRef.value as UniElement).getAttribute('value')}` + watchCountRes.value = `count: ${count.value}, count ref text (flush sync): ${countRef.value!.getAttribute('value')}` } else { watchCountRes.value = `count: ${count.value}, count ref text (flush sync): ` } @@ -99,7 +99,7 @@ const watchObjStrRes = ref('') watchEffect(() => { if (objStrRef.value !== null) { - watchObjStrRes.value = `str: ${obj.str}, obj.str ref text (flush pre): ${(objStrRef.value as UniElement).getAttribute('value')}` + watchObjStrRes.value = `str: ${obj.str}, obj.str ref text (flush pre): ${objStrRef.value!.getAttribute('value')}` } else { watchObjStrRes.value = `str: ${obj.str}, obj.str ref text (flush pre): ` } @@ -112,7 +112,7 @@ const watchObjBoolRes = ref('') watchEffect(() => { if (objBoolRef.value !== null) { - watchObjBoolRes.value = `bool: ${obj.bool}, obj.bool ref text (flush post): ${(objBoolRef.value as UniElement).getAttribute('value')}` + watchObjBoolRes.value = `bool: ${obj.bool}, obj.bool ref text (flush post): ${objBoolRef.value!.getAttribute('value')}` } else { watchObjBoolRes.value = `bool: ${obj.bool}, obj.bool ref text (flush post): ` } diff --git a/pages/composition-api/reactivity/watch-post-effect/watch-post-effect.uvue b/pages/composition-api/reactivity/watch-post-effect/watch-post-effect.uvue index 36189148d883d9434666b942a17bc23d07306a8f..aafbce0ce1abe7a56dcaaf013a740a30e28d31a7 100644 --- a/pages/composition-api/reactivity/watch-post-effect/watch-post-effect.uvue +++ b/pages/composition-api/reactivity/watch-post-effect/watch-post-effect.uvue @@ -42,7 +42,7 @@ arr : number[] } - const countRef = ref(null) + const countRef = ref(null) const count = ref(0) const watchCountRes = ref('') const watchCountCleanupRes = ref('') @@ -51,7 +51,7 @@ const stopWatchCount = watchPostEffect((onCleanup : OnCleanup) => { if (countRef.value !== null) { - watchCountRes.value = `count: ${count.value}, count ref text: ${(countRef.value as Element).getAttribute('value')}` + watchCountRes.value = `count: ${count.value}, count ref text: ${countRef.value!.getAttribute('value')}` } else { watchCountRes.value = `count: ${count.value}, count ref text: ` } @@ -94,11 +94,11 @@ watchObjRes.value = `obj: ${JSON.stringify(obj)}` }) - const objStrRef = ref(null) + const objStrRef = ref(null) const watchObjStrRes = ref('') watchPostEffect(() => { if (objStrRef.value !== null) { - watchObjStrRes.value = `str: ${obj.str}, obj.str ref text: ${(objStrRef.value as Element).getAttribute('value')}` + watchObjStrRes.value = `str: ${obj.str}, obj.str ref text: ${objStrRef.value!.getAttribute('value')}` } else { watchObjStrRes.value = `str: ${obj.str}, obj.str ref text: ` } diff --git a/pages/composition-api/reactivity/watch-sync-effect/watch-sync-effect.uvue b/pages/composition-api/reactivity/watch-sync-effect/watch-sync-effect.uvue index 7ec5199bac62c0f11ee2c471ad2833405c1208da..c5a8b4f44f663016e80bcdb924881aac428114f7 100644 --- a/pages/composition-api/reactivity/watch-sync-effect/watch-sync-effect.uvue +++ b/pages/composition-api/reactivity/watch-sync-effect/watch-sync-effect.uvue @@ -42,7 +42,7 @@ arr : number[] } - const countRef = ref(null) + const countRef = ref(null) const count = ref(0) const watchCountRes = ref('') const watchCountCleanupRes = ref('') @@ -51,7 +51,7 @@ const stopWatchCount = watchSyncEffect((onCleanup : OnCleanup) => { if (countRef.value !== null) { - watchCountRes.value = `count: ${count.value}, count ref text: ${(countRef.value as Element).getAttribute('value')}` + watchCountRes.value = `count: ${count.value}, count ref text: ${countRef.value!.getAttribute('value')}` } else { watchCountRes.value = `count: ${count.value}, count ref text: ` } @@ -94,11 +94,11 @@ watchObjRes.value = `obj: ${JSON.stringify(obj)}` }) - const objStrRef = ref(null) + const objStrRef = ref(null) const watchObjStrRes = ref('') watchSyncEffect(() => { if (objStrRef.value !== null) { - watchObjStrRes.value = `str: ${obj.str}, obj.str ref text: ${(objStrRef.value as Element).getAttribute('value')}` + watchObjStrRes.value = `str: ${obj.str}, obj.str ref text: ${objStrRef.value!.getAttribute('value')}` } else { watchObjStrRes.value = `str: ${obj.str}, obj.str ref text: ` } diff --git a/pages/composition-api/reactivity/watch/watch.uvue b/pages/composition-api/reactivity/watch/watch.uvue index e462968bf56eb6428ca6cddea340a5097f5f0f32..39a15b36e5d852ec198e32c791fb2ee8b8a501e5 100644 --- a/pages/composition-api/reactivity/watch/watch.uvue +++ b/pages/composition-api/reactivity/watch/watch.uvue @@ -50,8 +50,8 @@ const watchCountTrackNum = ref(0) const watchCountTriggerNum = ref(0) - const stopWatchCount = watch(count, (count : number, prevCount : number, onCleanup: OnCleanup) => { - watchCountRes.value = `count: ${count}, prevCount: ${prevCount}, count ref text (flush sync): ${(countRef.value as UniElement).getAttribute('value')}` + const stopWatchCount = watch(count, (count : number, prevCount : number, onCleanup : OnCleanup) => { + watchCountRes.value = `count: ${count}, prevCount: ${prevCount}, count ref text (flush sync): ${countRef.value!.getAttribute('value')}` const cancel = () => { watchCountCleanupRes.value = `watch count cleanup: ${count}` } @@ -88,14 +88,14 @@ // immediate: true 第一次触发, 旧值应该是 undefined, 现在 app 是初始值 const watchObjRes = ref('') - watch(obj, (obj : Obj, prevObj ?: Obj) => { + watch(obj, (obj : Obj, prevObj?: Obj) => { watchObjRes.value = `obj: ${JSON.stringify(obj)}, prevObj: ${JSON.stringify(prevObj)}` }, { immediate: true }) const objStrRef = ref(null) const watchObjStrRes = ref('') watch(() : string => obj.str, (str : string, prevStr : string) => { - watchObjStrRes.value = `str: ${str}, prevStr: ${prevStr}, obj.str ref text (flush pre): ${(objStrRef.value as UniElement).getAttribute('value')}` + watchObjStrRes.value = `str: ${str}, prevStr: ${prevStr}, obj.str ref text (flush pre): ${objStrRef.value!.getAttribute('value')}` }, { // 侦听器在组件渲染之前触发 flush: 'pre', @@ -104,7 +104,7 @@ const objBoolRef = ref(null) const watchObjBoolRes = ref('') watch(() : boolean => obj.bool, (bool : boolean, prevBool : boolean) => { - watchObjBoolRes.value = `bool: ${bool}, prevBool: ${prevBool}, obj.bool ref text (flush post): ${(objBoolRef.value as UniElement).getAttribute('value')}` + watchObjBoolRes.value = `bool: ${bool}, prevBool: ${prevBool}, obj.bool ref text (flush post): ${objBoolRef.value!.getAttribute('value')}` }, { // 侦听器延迟到组件渲染之后触发 flush: 'post'