- 引入react-monaco-editor
import Monaca from 'react-monaco-editor';
2、配置
const editorDidMountHandle = (editor: any, monaco: any) => {
editor.getAction('editor.action.formatDocument').run() //格式化
}
<Monaca
height={monacaHeight}
language="json"
theme="vs-light"
options={{ selectOnLineNumbers: true, automaticLayout: true, wordWrap: 'wordWrapColumn', wrappingStrategy: 'simple', wordWrapBreakBeforeCharacters: ',', wordWrapBreakAfterCharacters: ',', disableLayerHinting: true }}
value={config ? config : ''}
onChange={onChangeHandle}
editorDidMount={editorDidMountHandle}
/>
3、格式化成功后的效果