新しい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>
アプリケーションを実行すると、JavaScriptコンソールに次のように表示されます。
Could not create web worker(s). Falling back to loading web worker code in main thread, which might cause UI freezes. Please see https://github.com/Microsoft/monaco-editor#faq simpleWorker.js:31
You must define a function MonacoEnvironment.getWorkerUrl or MonacoEnvironment.getWorker 2 simpleWorker.js:33
Error: "Unexpected usage"
loadForeignModule editorSimpleWorker.js:494
_foreignProxy webWorker.js:54
languageFeatures.js:209
_doValidate languageFeatures.js:209
エラーを検索してみましたが、ほとんどのスレッドはfile:///を介してファイルにアクセスすることに焦点を合わせているようです(私が行っていない(ノードのWebサーバーにアクセスしています))。
さらに、高さが明示的に指定されていない限り、エディターは正しくレンダリングされません。これは予想される動作ではないと思います。
Vueでモナコエディターを正しく機能させるにはどうすればよいですか?サポートの理由で可能であれば、https://github.com/egoist/vue-monacoなどの非公式なサードパーティのラッパーは避けたいです。
Node / Vueの初心者です。