我尝试在open-wc中创建一个代码游乐场,并想使用Monaco Editor。问题是,我不能简单地对其进行整合。这是我尝试过的方法,它可以正常工作,但是性能却很糟糕。
updated(changedProperties) {
let container = this.shadowRoot.getElementById('container');
s
function loadScript(filename, callback) {
var fileref = document.createElement('script');
fileref.setAttribute("type", "text/javascript");
fileref.onload = callback;
fileref.setAttribute("src", filename);
if (typeof fileref != "undefined") {
document.getElementsByTagName("head")[0].appendChild(fileref)
}
}
loadScript('../node_modules/monaco-editor/min/vs/loader.js', function () {
require.config({paths: {'vs': '../node_modules/monaco-editor/min/vs'}});
require(['vs/editor/editor.main'], function () {
var editor = monaco.editor.create(container, {
value: [
'function x() {',
'\tconsole.log("Hello world!");',
'}'
].join('\n'),
language: 'javascript'
});
});
});
}
render() {
return html`
<h2> Monaco Editor Sample</h2>
<div id="container" style="width:100%;height:100%;border:1px solid grey"></div>
`;
}
答案 0 :(得分:0)
您需要使用Light Dom
才能使用它。
您必须将此添加到所有父母
createRenderRoot() {
return this;
}
您必须考虑到样式将停止工作,并且必须在
<style>
内用render()
替换样式