我创建了一个新的 vue 应用程序并运行npm install -s monaco-editor,然后我将 App.vue 更改为如下所示:
<template>
<div id="app" style="width: 500px; height: 500px;">
<div ref="editor" style="width: 500px; height: 500px;"></div>
</div>
</template>
<script>
import * as monaco from 'monaco-editor';
export default {
name: 'app',
async mounted() {
const el = this.$refs.editor;
this.editor = monaco.editor.create(el, {
value: "console.log('hello world');",
language: 'javascript',
});
},
};
</script>
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,我在 JavaScript 控制台中看到以下内容:
Could not create web worker(s). Falling back to loading web worker code in main thread, which might cause UI freezes. …Run Code Online (Sandbox Code Playgroud)