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 { ref, watch, toRaw, h, withDirectives, resolveDirective } from 'vue'
|
||||
import { ref, watch, toRaw, h, withDirectives, resolveDirective, defineAsyncComponent } from 'vue'
|
||||
const MonacoLoader = () => import('monaco-editor')
|
||||
|
||||
const WorkerImporters = {
|
||||
@@ -153,13 +153,18 @@ export const getLoadingDiv = (attrs = {}) => {
|
||||
|
||||
export default {
|
||||
install (app) {
|
||||
app.component(VueMonacoEditor.name, {
|
||||
setup (props) {
|
||||
if (loader.__getMonacoInstance() === null) {
|
||||
MonacoLoader().then(monaco => loader.config({ monaco }))
|
||||
app.component(VueMonacoEditor.name, defineAsyncComponent({
|
||||
loader: async () => {
|
||||
// 等待本地 Monaco 配置完成后再创建编辑器,避免触发默认 CDN 加载。
|
||||
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