Tôi đã tạo một ứng dụng vue mới và chạy npm install -s monaco-editor, sau đó tôi đã thay đổi App.vue của mình thành như sau:
<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>
Khi tôi chạy ứng dụng, tôi thấy các mục sau trong bảng điều khiển 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
Tôi đã thử tìm kiếm lỗi nhưng hầu hết các luồng dường như tập trung vào việc truy cập tệp qua tệp: /// mà tôi không làm (Tôi đang truy cập máy chủ web nút).
Ngoài ra, trình chỉnh sửa không hiển thị chính xác trừ khi chiều cao được chỉ định rõ ràng - Tôi không nghĩ đó là hành vi dự kiến.
Làm cách nào để làm cho trình soạn thảo monaco hoạt động chính xác trong Vue? Tôi muốn tránh các trình bao bọc của bên thứ ba không chính thức như https://github.com/egoist/vue-monaco nếu có thể vì lý do hỗ trợ.
Node / Vue newbie, vì vậy hãy tốt đẹp!