提交 88e65d34 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

types: 类型优化

上级 5a25e308
......@@ -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): `
}
......
......@@ -42,7 +42,7 @@
arr : number[]
}
const countRef = ref(null)
const countRef = ref<UniElement | null>(null)
const count = ref<number>(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<UniElement | null>(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: `
}
......
......@@ -42,7 +42,7 @@
arr : number[]
}
const countRef = ref(null)
const countRef = ref<UniElement | null>(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<UniElement | null>(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: `
}
......
......@@ -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<UniElement | null>(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<UniElement | null>(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'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册