鍍金池/ 問答/HTML/ react-monaco-editor 跨域問題

react-monaco-editor 跨域問題

項(xiàng)目引入了react-monaco編輯器但是前臺(tái)因?yàn)榭缬騿栴}顯示不出來,如何解決這是前臺(tái)的顯示頁面
clipboard.png

這是后臺(tái)的代碼

// Copyright 2017 The genesis-front Authors
// This file is part of the genesis-front library.
// 
// The genesis-front library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// The genesis-front library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with the genesis-front library. If not, see <http://www.gnu.org/licenses/>.

/// <reference types="monaco-editor" />

import * as React from 'react';
import styled from 'styled-components';
import MonacoEditor from 'react-monaco-editor';
import registerProtypo from './protypo';
import registerSimvolio from './simvolio';
import platform from 'lib/platform';

const StyledEditor = styled.div`
    &.editor-flex {
        display: flex;
        flex-direction: column;
        flex: 1;

        > .react-monaco-editor-container {
            flex: 1;
        }
    }
`;

interface IEditorProps {
    language?: string;
    value?: string;
    width?: number;
    height?: number;
    options?: monaco.editor.IEditorOptions;
    onChange?: (code: string) => void;
}

export default class Editor extends React.Component<IEditorProps> {
    public editor: monaco.editor.ICodeEditor;

    editorWillMount(editor: typeof monaco) {
        registerProtypo(editor);
        registerSimvolio(editor);
    }

    render() {
        return (
            <StyledEditor className={this.props.height ? null : 'editor-flex'}>
                <MonacoEditor
                    ref={l => this.editor = l && l.editor}
                    language={this.props.language}
                    value={this.props.value}
                    onChange={this.props.onChange && this.props.onChange.bind(this)}
                    editorWillMount={this.editorWillMount.bind(this)}
                    options={{
                        automaticLayout: true,
                        contextmenu: false,
                        scrollBeyondLastLine: false,
                        ...this.props.options
                    }}
                    height={this.props.height}
                    requireConfig={{
                        url: platform.select({
                            desktop: './vs/loader.js',
                            web: '/vs/loader.js'
                        }),
                        baseUrl: platform.select({
                            desktop: './',
                            web: '/'
                        }),
                        paths: {
                            'vs': './vs'
                        }
                    }}
                />
            </StyledEditor>
        );
    }
}
回答
編輯回答
玄鳥

這是調(diào)用你自己的API跨域了啊,和編輯器沒什么關(guān)系

2017年4月27日 16:25