mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(BackTop): should hide when deactivated (#11938)
* fix(site): don't cache components using teleport * feat: adapt keep-alive
This commit is contained in:
parent
5c9ce177f2
commit
803b471dbd
@ -9,6 +9,8 @@ import {
|
|||||||
type PropType,
|
type PropType,
|
||||||
type TeleportProps,
|
type TeleportProps,
|
||||||
type ExtractPropTypes,
|
type ExtractPropTypes,
|
||||||
|
onDeactivated,
|
||||||
|
onActivated,
|
||||||
} from 'vue';
|
} from 'vue';
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
@ -57,6 +59,7 @@ export default defineComponent({
|
|||||||
emits: ['click'],
|
emits: ['click'],
|
||||||
|
|
||||||
setup(props, { emit, slots, attrs }) {
|
setup(props, { emit, slots, attrs }) {
|
||||||
|
let shouldReshow = false;
|
||||||
const show = ref(false);
|
const show = ref(false);
|
||||||
const root = ref<HTMLElement>();
|
const root = ref<HTMLElement>();
|
||||||
const scrollParent = ref<Window | Element>();
|
const scrollParent = ref<Window | Element>();
|
||||||
@ -116,6 +119,22 @@ export default defineComponent({
|
|||||||
useEventListener('scroll', throttle(scroll, 100), { target: scrollParent });
|
useEventListener('scroll', throttle(scroll, 100), { target: scrollParent });
|
||||||
|
|
||||||
onMounted(updateTarget);
|
onMounted(updateTarget);
|
||||||
|
|
||||||
|
onActivated(() => {
|
||||||
|
if (shouldReshow) {
|
||||||
|
show.value = true;
|
||||||
|
shouldReshow = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
onDeactivated(() => {
|
||||||
|
// teleported back-top should be hide when deactivated
|
||||||
|
if (show.value && props.teleport) {
|
||||||
|
show.value = false;
|
||||||
|
shouldReshow = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
watch(() => props.target, updateTarget);
|
watch(() => props.target, updateTarget);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user