在vue中使用codemirror格式化JSON

1. 下载指定版本的包 (避免引发不必要的错误)

yarn add codemirror@^5.64.0

2. 导入需要的文件


  import CodeMirror from 'codemirror'
  import 'codemirror/addon/lint/lint.css'
  import 'codemirror/addon/fold/foldgutter.css'
  import 'codemirror/lib/codemirror.css'
  import 'codemirror/theme/rubyblue.css'
  import 'codemirror/mode/javascript/javascript'
  import 'codemirror/addon/lint/lint'
  import 'codemirror/addon/lint/json-lint'

  // 折叠
  import 'codemirror/addon/fold/foldgutter.css'
  import 'codemirror/addon/fold/foldcode'
  import 'codemirror/addon/fold/foldgutter'
  import 'codemirror/addon/fold/brace-fold'
  import 'codemirror/addon/fold/comment-fold'

3. 注册





4. 效果

在vue中使用codemirror格式化JSON_第1张图片

 

你可能感兴趣的:(vue.js,json,前端)