fix(BackTop): should hide when deactivated (#11938)

* fix(site): don't cache components using teleport

* feat: adapt keep-alive
This commit is contained in:
zqran
2023-06-10 12:18:45 +08:00
committed by GitHub
parent 5c9ce177f2
commit 803b471dbd
+19
View File
@@ -9,6 +9,8 @@ import {
type PropType,
type TeleportProps,
type ExtractPropTypes,
onDeactivated,
onActivated,
} from 'vue';
// Utils
@@ -57,6 +59,7 @@ export default defineComponent({
emits: ['click'],
setup(props, { emit, slots, attrs }) {
let shouldReshow = false;
const show = ref(false);
const root = ref<HTMLElement>();
const scrollParent = ref<Window | Element>();
@@ -116,6 +119,22 @@ export default defineComponent({
useEventListener('scroll', throttle(scroll, 100), { target: scrollParent });
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);
return () => {