我在javascript香草web组件中使用摩纳哥编辑:
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
class CodeEditor extends HTMLElement {
constructor() {
super();
this.css = (...)
this.html = (...)
}
connectedCallback() {
this.attachShadow({
mode: 'open'
});
const root = this.getRootElement();
this.shadowRoot.append(this.getStyles(), root);
this.editor = monaco.editor.create(root, {
value: this.getExampleCode(),
language: 'javascript',
theme: 'vs-dark',
});
}
getRootElement() { return (...) //creates a template dom element and returns it}
getStyles() {return (...)}
getExampleCode() {return (...)}
}
window.customElements.define('code-editor', CodeEditor);并在我的HTML中使用如下:
<div id="code-editor" class="code-editor">
<code-editor></code-editor>
</div>其结果就是这样的混乱:

https://stackoverflow.com/questions/67426420
复制相似问题