安装
github:https://github.com/securingsincity/react-ace
文档:https://github.com/securingsincity/react-ace/blob/master/docs/Ace.md
定义:https://github.com/securingsincity/react-ace/blob/master/docs/Ace.md
npm:https://www.npmjs.com/package/react-ace
命令:npm install react-ace
简单使用
<AceEditor
mode="js"
readOnly={false}
theme="monokai"
name="app_code_editor"
onChange={this.onChange}
fontSize={16}
showPrintMargin
showGutter
highlightActiveLine //突出活动线
enableSnippets //启用代码段
value={this.state.value}
setAutoScrollEditorIntoView
style={{width: '100%', height: this.state.deskHeight, minHeight: 600}}
editorProps={{ $blockScrolling: true }}
setOptions={{
maxLines: 30,
tabSize: 4
}}
/>
主题
npm i ace-builds -S
import ReactAce from 'react-ace';
import "ace-builds/src-noconflict/mode-json"; // 引入模式
import "ace-builds/src-noconflict/theme-monokai"; // 引入主题
<ReactAce
// width="100%"
// height="400px"
style={{ width: '100%', height: 400, minHeight: 400 }}
showPrintMargin={false}
mode="json"
theme="monokai"
onChange={onChangeAce}
name="UNIQUE_ID_OF_DIV"
editorProps={{ $blockScrolling: true }}
value={aceValue}
fontSize={16}
setAutoScrollEditorIntoView
setOptions={{
maxLines: 30,
enableBasicAutocompletion: false,
enableLiveAutocompletion: false,
enableSnippets: false,
showLineNumbers: true,
tabSize: 2,
}}
readOnly={false}
showGutter={true}
highlightActiveLine={true}
/>
注意
务必加上 setAutoScrollEditorIntoView={true},否则会有一些滚动方面的问题
参考资料
https://www.jianshu.com/p/607883e9aeb4
https://blog.csdn.net/wsh2467991332/article/details/90904332
React Ace 组件与其同类型相比较