|
@@ -1,25 +1,34 @@
|
|
|
<template>
|
|
<template>
|
|
|
<div style="height: 400px;">
|
|
<div style="height: 400px;">
|
|
|
- <CodeEditor v-model:value="code" language="javascript" theme="vs-dark" :options="editorOptions" />
|
|
|
|
|
|
|
+ <CodeEditor v-model:value="code" language="javascript" theme="vs-dark" :options="editorOptions" @editor-did-mount="editorDidMount" />
|
|
|
</div>
|
|
</div>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
|
import { ref } from 'vue';
|
|
import { ref } from 'vue';
|
|
|
-// import { CodeEditor } from 'monaco-editor-vue3';
|
|
|
|
|
|
|
+import type { EditorOptions } from 'monaco-editor-vue3';
|
|
|
|
|
+import type { editor } from 'monaco-editor'
|
|
|
|
|
+import { rules } from 'unocss/preset-wind4';
|
|
|
|
|
+
|
|
|
|
|
+const monacoEditor = await import('monaco-editor')
|
|
|
|
|
|
|
|
// 改为动态载入,提升加载速度
|
|
// 改为动态载入,提升加载速度
|
|
|
const CodeEditor = defineAsyncComponent(() =>
|
|
const CodeEditor = defineAsyncComponent(() =>
|
|
|
import('monaco-editor-vue3')
|
|
import('monaco-editor-vue3')
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
|
|
+const editorDidMount = (editor: editor.IStandaloneCodeEditor) => {
|
|
|
|
|
+ editor
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
const code = ref(`function hello() {
|
|
const code = ref(`function hello() {
|
|
|
console.log('Hello, Monaco Editor Vue3!');
|
|
console.log('Hello, Monaco Editor Vue3!');
|
|
|
}`);
|
|
}`);
|
|
|
|
|
|
|
|
-const editorOptions = {
|
|
|
|
|
|
|
+const editorOptions: EditorOptions = {
|
|
|
fontSize: 14,
|
|
fontSize: 14,
|
|
|
minimap: { enabled: false },
|
|
minimap: { enabled: false },
|
|
|
- automaticLayout: true
|
|
|
|
|
|
|
+ automaticLayout: true,
|
|
|
|
|
+
|
|
|
};
|
|
};
|
|
|
</script>
|
|
</script>
|