Skip to content

Commit

Permalink
feat: fuck vue2
Browse files Browse the repository at this point in the history
  • Loading branch information
lvjiaxuan committed May 28, 2023
1 parent c2f809a commit b3fe6c0
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -68,10 +69,10 @@ export default defineComponent({

methods: {
roll() {
rollForVue2 && rollForVue2()
rollInVue2 && rollInVue2()
},
reset() {
resetForVue2 && resetForVue2()
resetInVue2 && resetInVue2()
},
},

Expand All @@ -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'
})`,
}
}
}

Expand Down Expand Up @@ -134,8 +145,8 @@ export default defineComponent({
expose({ roll, reset: init })

if (isVue2) {
rollForVue2 = roll
resetForVue2 = init
rollInVue2 = roll
resetInVue2 = init
}

return () => h(
Expand Down

0 comments on commit b3fe6c0

Please sign in to comment.