1
0
mirror of https://github.com/sendevia/website.git synced 2026-03-08 00:32:34 +08:00

fix: SSR compatibility

This commit is contained in:
2025-10-21 18:20:16 +08:00
parent 1e5a62d248
commit 9ebd824366
4 changed files with 27 additions and 18 deletions

View File

@@ -6,9 +6,11 @@ const { page, frontmatter, theme } = useGlobalData();
const seed = ref(1);
const defaultImpression = theme.value.defaultImpression;
onMounted(() => {
seed.value = Date.now();
});
if (typeof window !== "undefined") {
onMounted(() => {
seed.value = Date.now();
});
}
</script>
<template>

View File

@@ -2,7 +2,7 @@
import { ref, onMounted, onBeforeUnmount } from "vue";
const visible = ref(false);
let container: HTMLElement | Window = window;
let container: HTMLElement | Window | null = null;
function isScrollable(el: HTMLElement) {
const style = window.getComputedStyle(el);
@@ -33,19 +33,21 @@ function scrollToTop() {
}
}
onMounted(() => {
container = detectContainer();
const target: any = container;
target.addEventListener("scroll", onScroll, { passive: true });
if (container !== window) window.addEventListener("scroll", onScroll, { passive: true });
onScroll();
});
if (typeof window !== "undefined") {
onMounted(() => {
container = detectContainer();
const target: any = container;
target.addEventListener("scroll", onScroll, { passive: true });
if (container !== window) window.addEventListener("scroll", onScroll, { passive: true });
onScroll();
});
onBeforeUnmount(() => {
const target: any = container;
target.removeEventListener("scroll", onScroll);
if (container !== window) window.removeEventListener("scroll", onScroll);
});
onBeforeUnmount(() => {
const target: any = container;
target.removeEventListener("scroll", onScroll);
if (container !== window) window.removeEventListener("scroll", onScroll);
});
}
</script>
<template>

View File

@@ -7,7 +7,10 @@ function copyAnchorLink(this: HTMLElement) {
const anchor = this as HTMLAnchorElement;
const href = anchor.getAttribute("href");
const fullUrl = `${window.location.origin}${window.location.pathname}${href}`;
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(fullUrl);
}
const hiddenSpan = anchor.querySelector<HTMLSpanElement>("span.visually-hidden");
if (hiddenSpan) {

View File

@@ -88,11 +88,13 @@ const currentLayout = computed(() => {
const route = useRoute();
onMounted(updatePalette);
function onAfterEnter() {
updatePalette();
}
if (typeof window !== "undefined") {
onMounted(updatePalette);
}
</script>
<template>