mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
fix(components): [scrollbar] restore scroll position in onActivated hook (#11363)
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
import {
|
||||
computed,
|
||||
nextTick,
|
||||
onActivated,
|
||||
onMounted,
|
||||
onUpdated,
|
||||
provide,
|
||||
@@ -57,6 +58,8 @@ const ns = useNamespace('scrollbar')
|
||||
|
||||
let stopResizeObserver: (() => void) | undefined = undefined
|
||||
let stopResizeListener: (() => void) | undefined = undefined
|
||||
let wrapScrollTop = 0
|
||||
let wrapScrollLeft = 0
|
||||
|
||||
const scrollbarRef = ref<HTMLDivElement>()
|
||||
const wrapRef = ref<HTMLDivElement>()
|
||||
@@ -85,6 +88,8 @@ const resizeKls = computed(() => {
|
||||
const handleScroll = () => {
|
||||
if (wrapRef.value) {
|
||||
barRef.value?.handleScroll(wrapRef.value)
|
||||
wrapScrollTop = wrapRef.value.scrollTop
|
||||
wrapScrollLeft = wrapRef.value.scrollLeft
|
||||
|
||||
emit('scroll', {
|
||||
scrollTop: wrapRef.value.scrollTop,
|
||||
@@ -160,6 +165,11 @@ provide(
|
||||
})
|
||||
)
|
||||
|
||||
onActivated(() => {
|
||||
wrapRef.value!.scrollTop = wrapScrollTop
|
||||
wrapRef.value!.scrollLeft = wrapScrollLeft
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
if (!props.native)
|
||||
nextTick(() => {
|
||||
|
||||
Reference in New Issue
Block a user