Skip to content

Commit d057607

Browse files
docs: ✏️ 优化文档与演示demo同步暗黑模式的逻辑
Closes: #210
1 parent e50cccc commit d057607

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

docs/.vitepress/theme/components/frame.vue

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<script setup lang="ts">
66
import { useRoute, useData } from 'vitepress';
7-
import { computed, watch } from 'vue'
7+
import { computed, onMounted, watch } from 'vue'
88
const baseUrl = process.env.NODE_ENV === 'production' ? `${location.origin}/demo/?timestamp=${new Date().getTime()}#/` : 'http://localhost:5173/demo/#/'
99
1010
const route = useRoute()
@@ -22,11 +22,22 @@ const href = computed(() => {
2222
2323
const vitepressData = useData()
2424
25+
onMounted(() => {
26+
setTimeout(() => {
27+
ssendMessage()
28+
}, 500);
29+
})
30+
2531
2632
watch(() => vitepressData.isDark.value, () => {
33+
ssendMessage()
34+
})
35+
36+
function ssendMessage(){
2737
const iFrame: any = document.getElementById('demo')
2838
iFrame && iFrame.contentWindow.postMessage(vitepressData.isDark.value, href.value)
29-
})
39+
40+
}
3041
3142
function kebabToCamel(input: string): string {
3243
return input.replace(/-([a-z])/g, (match, group) => group.toUpperCase());

0 commit comments

Comments
 (0)