0

我跟着这个 tu

https://www.programmersought.com/article/39525453236/

除了标题什么都不显示

            require.config({ paths: { 'vs': '../node_modules/monaco-editor/min/vs' } });
        require(['vs/editor/editor.main'], function () {

            // Initialize variables
            var fileCounter = 0;
            var editorArray = [];
            var defaultCode = [
                'function helloWorld() {',
                '   console.log("Hello world!");',
                '}'
            ].join('\n');

            // define editor theme
            monaco.editor.defineTheme('myTheme', {
                base: 'vs',
                inherit: true,
                rules: [{ background: 'EDF9FA' }],
            });
            monaco.editor.setTheme('myTheme');

            // Create a new editor
            function newEditor(container_id, code, language) {
                var model = monaco.editor.createModel(code, language);
                var editor = monaco.editor.create(document.getElementById(container_id), {
                    model: model,
                });
                editorArray.push(editor);
                return editor;
            }

            // Create a new div
            function addNewEditor(code, language) {
                var new_container = document.createElement("DIV");
                new_container.id = "container-" + fileCounter.toString(10);
                new_container.className = "container";
                document.getElementById("root").appendChild(new_container);
                newEditor(new_container.id, code, language);
                fileCounter += 1;
            }

            addNewEditor(defaultCode, 'javascript');

        });
4

0 回答 0