Rap 原分销系统代码Web
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

7a6b097a5d8bec2811dec9f72ad4aec4ecc1a0cf.svn-base 1.5KB

пре 5 месеци
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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/clike/clike'
  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-java',
  42. lineNumbers: true,
  43. lint: true,
  44. lineWrapping: true,
  45. tabSize: 2,
  46. cursorHeight: 0.9,
  47. // 替换主题这里需修改名称
  48. theme: 'idea',
  49. readOnly: true
  50. })
  51. this.editor.setSize('auto', this.height)
  52. this.editor.setValue(this.value)
  53. },
  54. methods: {
  55. getValue() {
  56. return this.editor.getValue()
  57. }
  58. }
  59. }
  60. </script>
  61. <style scoped>
  62. .json-editor{
  63. height: 100%;
  64. margin-bottom: 10px;
  65. }
  66. .json-editor >>> .CodeMirror {
  67. font-size: 14px;
  68. overflow-y:auto;
  69. font-weight:normal
  70. }
  71. .json-editor >>> .CodeMirror-scroll{
  72. }
  73. .json-editor >>> .cm-s-rubyblue span.cm-string {
  74. color: #F08047;
  75. }
  76. </style>