【发布时间】:2018-08-13 16:06:00
【问题描述】:
我在我的项目中添加了react-codemirror2,但是尽管我导入了codemirror.css 文件,但它并没有加载css,因为它提到css 应该以某种方式应用到组件中(mentioned here),但长话短说它仍然呈现如下:
Code Mirror with no CSS
我真的不知道问题是什么。所以这是我的代码:
import { connect } from 'react-redux';
import 'codemirror/lib/codemirror.css';
import 'codemirror/theme/material.css';
import { Controlled as CodeMirror } from 'react-codemirror2';
require('codemirror/mode/xml/xml');
require('codemirror/mode/javascript/javascript');
class MyComponent extends Component {
handleValueChange = value => this.props.onUpdateValue({ value });
render() {
const { shade } = this.props;
const myOptions = {
mode: 'xml',
theme: shade === 'dark' ? 'material' : 'default',
lineNumbers: true,
}
return (
<CodeMirror
id="editor"
value={this.props.value}
options={myOptions}
onBeforeChange={(editor, data, value) => {
this.handleValueChange(value);
}}
onChange={(editor, data, value) => {}}
/>
);
}
}
function mapStateToProps(state) {
return {
shade: state.muiTheme.shade,
};
}
export default connect(
mapStateToProps,
null
)(MyComponent);
我还尝试@import 我项目的global.css 文件中的css 文件(如下所示),但没有任何改变。
@import '/node_modules/codemirror/lib/codemirror.css';
@import '/node_modules/codemirror/theme/material.css';
我真的不知道还应该尝试什么或我做错了什么,因为它不应该是非常特别的东西。所以我在问你,任何建议都会有所帮助。
谢谢:)
【问题讨论】:
标签: reactjs codemirror react-codemirror