fix
This commit is contained in:
11
src/App.vue
11
src/App.vue
@@ -6,9 +6,9 @@ import "./index.css"
|
|||||||
const isDark = useDark()
|
const isDark = useDark()
|
||||||
|
|
||||||
// 延迟加载 highlight.js,避免阻塞首屏
|
// 延迟加载 highlight.js,避免阻塞首屏
|
||||||
let hljsInstance: any = null
|
const hljsInstance = ref<any>(null)
|
||||||
const loadHighlightJS = async () => {
|
const loadHighlightJS = async () => {
|
||||||
if (hljsInstance) return hljsInstance
|
if (hljsInstance.value) return hljsInstance.value
|
||||||
|
|
||||||
const hljs = (await import("highlight.js/lib/core")).default
|
const hljs = (await import("highlight.js/lib/core")).default
|
||||||
const c = (await import("highlight.js/lib/languages/c")).default
|
const c = (await import("highlight.js/lib/languages/c")).default
|
||||||
@@ -19,7 +19,7 @@ const loadHighlightJS = async () => {
|
|||||||
hljs.registerLanguage("python", python)
|
hljs.registerLanguage("python", python)
|
||||||
hljs.registerLanguage("cpp", cpp)
|
hljs.registerLanguage("cpp", cpp)
|
||||||
|
|
||||||
hljsInstance = hljs
|
hljsInstance.value = hljs
|
||||||
return hljs
|
return hljs
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,10 +32,7 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
provide(
|
provide("hljs", hljsInstance)
|
||||||
"hljs",
|
|
||||||
computed(() => hljsInstance),
|
|
||||||
)
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
Reference in New Issue
Block a user