Skip to content

Commit

Permalink
fix(ui/swipe): 增加resize方法
Browse files Browse the repository at this point in the history
affects: @varlet/ui
  • Loading branch information
haoziqaq committed Jan 28, 2021
1 parent 40fcb2e commit a453b66
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
28 changes: 11 additions & 17 deletions packages/varlet-ui/src/swipe/Swipe.vue
Original file line number Diff line number Diff line change
Expand Up @@ -298,23 +298,16 @@ export default defineComponent({
props.onChange?.(index.value)
}
watch(
() => length.value,
() => {
initialIndex()
startAutoplay()
trackSize.value = size.value * length.value
}
)
watch(
() => swipeEl.value,
() => {
size.value = props.vertical
? (swipeEl.value as HTMLElement).offsetHeight
: (swipeEl.value as HTMLElement).offsetWidth
}
)
const resize = () => {
size.value = props.vertical
? (swipeEl.value as HTMLElement).offsetHeight
: (swipeEl.value as HTMLElement).offsetWidth
trackSize.value = size.value * length.value
initialIndex()
startAutoplay()
}
watch(() => length.value, resize)
onUnmounted(stopAutoplay)
Expand All @@ -338,6 +331,7 @@ export default defineComponent({
next,
prev,
to,
resize,
}
},
})
Expand Down
1 change: 1 addition & 0 deletions packages/varlet-ui/src/swipe/example/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default defineComponent({
setup() {
return {
swipe: ref(null),
s: ref(false),
log(index: number) {
console.log(index)
},
Expand Down

0 comments on commit a453b66

Please sign in to comment.