mirror of
https://github.com/fugary/simple-element-plus-template.git
synced 2026-11-12 06:43:53 +00:00
fix(ui): 修复 Monaco 异步初始化触发远程加载
This commit is contained in:
Vendored
+13
-8
@@ -1,5 +1,5 @@
|
|||||||
import VueMonacoEditor, { loader } from '@guolao/vue-monaco-editor'
|
import VueMonacoEditor, { loader } from '@guolao/vue-monaco-editor'
|
||||||
import { ref, watch, toRaw, h, withDirectives, resolveDirective } from 'vue'
|
import { ref, watch, toRaw, h, withDirectives, resolveDirective, defineAsyncComponent } from 'vue'
|
||||||
const MonacoLoader = () => import('monaco-editor')
|
const MonacoLoader = () => import('monaco-editor')
|
||||||
|
|
||||||
const WorkerImporters = {
|
const WorkerImporters = {
|
||||||
@@ -153,13 +153,18 @@ export const getLoadingDiv = (attrs = {}) => {
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
install (app) {
|
install (app) {
|
||||||
app.component(VueMonacoEditor.name, {
|
app.component(VueMonacoEditor.name, defineAsyncComponent({
|
||||||
setup (props) {
|
loader: async () => {
|
||||||
if (loader.__getMonacoInstance() === null) {
|
// 等待本地 Monaco 配置完成后再创建编辑器,避免触发默认 CDN 加载。
|
||||||
MonacoLoader().then(monaco => loader.config({ monaco }))
|
const monaco = await MonacoLoader()
|
||||||
|
loader.config({ monaco })
|
||||||
|
return {
|
||||||
|
setup (props) {
|
||||||
|
return () => h(VueMonacoEditor, props, () => [getLoadingDiv()])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return () => h(VueMonacoEditor, props, () => [getLoadingDiv()])
|
},
|
||||||
}
|
loadingComponent: { render: () => getLoadingDiv() }
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user