1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
| <template> <div> <textarea ref="mycode" :value="sqlValue"> </textarea> </div> </template> <script> import "codemirror/theme/ambiance.css"; import "codemirror/lib/codemirror.css"; import "codemirror/addon/hint/show-hint.css"; import CodeMirror from "codemirror"; import "codemirror/addon/edit/matchbrackets"; import "codemirror/addon/selection/active-line"; import "codemirror/mode/sql/sql"; import "codemirror/addon/hint/show-hint"; import "codemirror/addon/hint/sql-hint"; export default { data() { return { editor: null, }; }, props: { sqlValue: { type: String, default: "", }, sqlStyle: { type: String, default: "default", }, readOnly: { type: [Boolean, String], }, }, watch: { newVal() { if (this.editor) { this.$emit("changeTextarea", this.editor.getValue()); } }, }, computed: { newVal() { if (this.editor) { return this.editor.getValue(); } else { return ""; } }, }, mounted() { let mime = "text/x-mariadb"; this.editor = CodeMirror.fromTextArea(this.$refs.mycode, { value: this.sqlValue, mode: mime, indentWithTabs: true, smartIndent: true, lineNumbers: true, matchBrackets: true, cursorHeight: 1, lineWrapping: true, readOnly: this.readOnly, theme: this.sqlStyle, extraKeys: { Ctrl: "autocomplete" }, hintOptions: { completeSingle: false, }, }); this.editor.on("inputRead", () => { this.editor.showHint(); }); }, methods: { setVal() { if (this.editor) { if (this.sqlValue === "") { this.editor.setValue(""); } else { this.editor.setValue(this.sqlValue); } } }, }, }; </script> <style> .CodeMirror { color: black; direction: ltr; line-height: 22px; text-align: left; border: 1px solid #f3f3f3; } .CodeMirror-hints { z-index: 9999 !important; } </style>
|