From 88e65d3433ca8e8dded16bf3ba8eb1fc13851104 Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Thu, 18 Jan 2024 17:33:32 +0800 Subject: [PATCH] =?UTF-8?q?types:=20=E7=B1=BB=E5=9E=8B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reactivity/watch-effect/watch-effect.uvue | 8 ++++---- .../watch-post-effect/watch-post-effect.uvue | 8 ++++---- .../watch-sync-effect/watch-sync-effect.uvue | 8 ++++---- pages/composition-api/reactivity/watch/watch.uvue | 10 +++++----- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/pages/composition-api/reactivity/watch-effect/watch-effect.uvue b/pages/composition-api/reactivity/watch-effect/watch-effect.uvue index 05e37b6..5e666bf 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 3618914..aafbce0 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 7ec5199..c5a8b4f 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 e462968..39a15b3 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' -- GitLab