react-monaco-editor格式化
作者:互联网
- 引入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、格式化成功后的效果
标签:格式化,react,editor,monaco,true,any 来源: https://blog.csdn.net/qq_37233023/article/details/122309149