Files
cwd/docs/.vitepress/components/footerDoc.vue
anghunk 34072b33d0 fix(样式): 修复暗黑主题下评论组件边框显示问题
修复评论组件在暗黑主题下边框显示异常的问题:
- 移除评论头部的固定底部边框,改由主题变量控制
- 修正主题变量作用域,确保变量在容器内生效
- 优化主题初始化逻辑,默认使用亮色主题
- 添加主题切换监听,支持动态切换亮色/暗黑主题
2026-01-27 11:31:02 +08:00

57 lines
1.3 KiB
Vue

<template>
<div id="comments" ref="commentsRoot"></div>
</template>
<script setup>
import { onMounted, ref, watch } from "vue";
import { useData } from "vitepress";
const commentsRoot = ref(null);
const commentsInstance = ref(null);
const { isDark } = useData();
const getTheme = () => (isDark.value ? "dark" : "light");
onMounted(async () => {
if (!commentsRoot.value || typeof window === "undefined") return;
const apiBaseUrl = "https://cwd-api.zishu.me";
if (!apiBaseUrl) return;
if (!window.CWDComments) {
await new Promise((resolve, reject) => {
const script = document.createElement("script");
script.src = "https://cwd.js.org/cwd.js";
script.async = true;
script.onload = () => resolve();
script.onerror = (e) => reject(e);
document.head.appendChild(script);
}).catch(() => {});
}
if (!window.CWDComments) return;
const comments = new window.CWDComments({
el: commentsRoot.value,
apiBaseUrl,
theme: getTheme(),
});
commentsInstance.value = comments;
comments.mount();
watch(
isDark,
(value) => {
if (!commentsInstance.value) return;
commentsInstance.value.updateConfig({
theme: value ? "dark" : "light",
});
},
{ immediate: false }
);
});
</script>