Rap 原分销系统代码Web
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.6KB

  1. <template>
  2. <div class="json-editor">
  3. <textarea ref="textarea" />
  4. </div>
  5. </template>
  6. <script>
  7. import CodeMirror from 'codemirror'
  8. import 'codemirror/lib/codemirror.css'
  9. // 替换主题这里需修改名称
  10. import 'codemirror/theme/idea.css'
  11. import 'codemirror/mode/yaml/yaml'
  12. export default {
  13. props: {
  14. value: {
  15. type: String,
  16. required: true
  17. },
  18. height: {
  19. type: String,
  20. required: true
  21. }
  22. },
  23. data() {
  24. return {
  25. editor: false
  26. }
  27. },
  28. watch: {
  29. value(value) {
  30. const editorValue = this.editor.getValue()
  31. if (value !== editorValue) {
  32. this.editor.setValue(this.value)
  33. }
  34. },
  35. height(value) {
  36. this.editor.setSize('auto', this.height)
  37. }
  38. },
  39. mounted() {
  40. this.editor = CodeMirror.fromTextArea(this.$refs.textarea, {
  41. mode: 'text/x-yaml',
  42. lineNumbers: true,
  43. lint: true,
  44. lineWrapping: true,
  45. tabSize: 2,
  46. cursorHeight: 0.9,
  47. // 替换主题这里需修改名称
  48. theme: 'idea'
  49. })
  50. this.editor.setSize('auto', this.height)
  51. this.editor.setValue(this.value)
  52. this.editor.on('change', cm => {
  53. this.$emit('changed', cm.getValue())
  54. this.$emit('input', cm.getValue())
  55. })
  56. },
  57. methods: {
  58. getValue() {
  59. return this.editor.getValue()
  60. }
  61. }
  62. }
  63. </script>
  64. <style scoped>
  65. .json-editor{
  66. height: 100%;
  67. margin-bottom: 10px;
  68. }
  69. .json-editor >>> .CodeMirror {
  70. font-size: 13px;
  71. overflow-y:auto;
  72. font-weight:normal
  73. }
  74. .json-editor >>> .CodeMirror-scroll{
  75. }
  76. .json-editor >>> .cm-s-rubyblue span.cm-string {
  77. color: #F08047;
  78. }
  79. </style>