Adding CodeMirror to Shadow Dom of Custom Element?

前端 未结 1 1920
轻奢々
轻奢々 2021-01-22 02:18

I\'d like to dynamically create a CodeMirror instance inside a Custom Element and have it live inside the element\'s Shadow DOM. For example:

         


        
相关标签:
1条回答
  • 2021-01-22 02:34

    Import CodeMirror's stylesheet inside the shadow DOM with @import url:

    constructor() {
        super();
        let shadowRoot = this.attachShadow({ mode: 'open' });
        shadowRoot.innerHTML = `
            <style>
               @import url(https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.24.2/codemirror.min.css)
            </style>`         
    }
    
    0 讨论(0)
提交回复
热议问题