fix(样式): 修复暗黑主题下评论组件边框显示问题
修复评论组件在暗黑主题下边框显示异常的问题: - 移除评论头部的固定底部边框,改由主题变量控制 - 修正主题变量作用域,确保变量在容器内生效 - 优化主题初始化逻辑,默认使用亮色主题 - 添加主题切换监听,支持动态切换亮色/暗黑主题
This commit is contained in:
@@ -3,9 +3,14 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onMounted, ref } from "vue";
|
||||
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;
|
||||
@@ -30,8 +35,22 @@ onMounted(async () => {
|
||||
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>
|
||||
|
||||
Reference in New Issue
Block a user