From b3fe6c0313785da1e76b9d27f81c099db3a4a75a Mon Sep 17 00:00:00 2001 From: lvjiaxuan <11309921+lvjiaxuan@users.noreply.github.com> Date: Sun, 28 May 2023 16:49:40 +0800 Subject: [PATCH] feat: fuck vue2 --- src/index.ts | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/index.ts b/src/index.ts index dbed25d..ccaed34 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,11 +5,12 @@ import { isVue2, onMounted, ref, + set, watch, } from 'vue-demi' -let rollForVue2: () => unknown -let resetForVue2: () => unknown +let rollInVue2: () => unknown +let resetInVue2: () => unknown export default defineComponent({ name: 'VueNumberRoll', @@ -68,10 +69,10 @@ export default defineComponent({ methods: { roll() { - rollForVue2 && rollForVue2() + rollInVue2 && rollInVue2() }, reset() { - resetForVue2 && resetForVue2() + resetInVue2 && resetInVue2() }, }, @@ -97,12 +98,22 @@ export default defineComponent({ (vueNumberRollRef.value?.children[0]?.children[0]?.children[0] as HTMLElement)?.offsetHeight ?? 0) function setItemTranslateY(idx: number, number: number) { - itemTranslateYs.value[idx] = { - transform: `translateY(${ - (props.reverseRollDirection - ? (number - 9) * itemHeightNumber.value - : -number * itemHeightNumber.value).toString() + 'px' - })`, + if (!isVue2) { + set(itemTranslateYs.value, idx, { + transform: `translateY(${ + (props.reverseRollDirection + ? (number - 9) * itemHeightNumber.value + : -number * itemHeightNumber.value).toString() + 'px' + })`, + }) + } else { + itemTranslateYs.value[idx] = { + transform: `translateY(${ + (props.reverseRollDirection + ? (number - 9) * itemHeightNumber.value + : -number * itemHeightNumber.value).toString() + 'px' + })`, + } } } @@ -134,8 +145,8 @@ export default defineComponent({ expose({ roll, reset: init }) if (isVue2) { - rollForVue2 = roll - resetForVue2 = init + rollInVue2 = roll + resetInVue2 = init } return () => h(