7
7
8
8
9
9
# Vue-Codemirror
10
- Codemirror components for Vue.js
10
+ Codemirror component for Vue.js(1.x ~ 2.x),本组件基于 [ Codemirror] ( http://codemirror.net/ ) 构建,支持Vue全版本使用,支持100+多种语言、分支语言、语法,支持多种代码高亮theme,并可以自行配置,可使用Vue-Codemirror快速轻易构建出多种丰富全面的web code editor,并以此基础多次开发WebIDE,欢迎加入前端技术交流群:288325802
11
+
11
12
12
13
13
14
# Example
14
15
15
- [ Demos ] ( https://surmon-china.github.io/vue-codemirror )
16
+ [ Demo Page ] ( https://surmon-china.github.io/vue-codemirror )
16
17
17
18
18
19
# Use Setup
19
20
21
+
22
+ ### install vue-codemirror
23
+
20
24
``` bash
21
- # install vue-codemirror
22
25
npm install vue-codemirror --save
23
26
```
24
27
@@ -39,6 +42,22 @@ var CodeMirror = require('vue-codemirror')
39
42
40
43
// use
41
44
Vue .use (CodeMirror)
45
+
46
+
47
+ // --------------------------------------
48
+
49
+
50
+ // or use with component(ES6)
51
+ import Vue from ' vue'
52
+ // ...
53
+ import { codemirror } from ' vue-codemirror'
54
+
55
+ // use
56
+ export default {
57
+ components: {
58
+ codemirror
59
+ }
60
+ }
42
61
```
43
62
44
63
@@ -48,12 +67,16 @@ Vue.use(CodeMirror)
48
67
<codemirror ></codemirror >
49
68
50
69
51
- <!-- component data bind -->
70
+ <!-- component data bind(Vue.js1.X) -->
52
71
<codemirror :code.sync =" code" ></codemirror >
53
72
54
73
55
- <!-- component config example 1 -->
74
+ <!-- component config example 1(Vue.js1.X) -->
56
75
<codemirror :code.sync =" code" :options =" editorOption" ></codemirror >
76
+
77
+
78
+ <!-- in vue.js2.X .once and .sync are deprecated, parent component needs to explicitly emit an event instead of relying on implicit binding -->
79
+ <codemirror :code =" code" :options =" editorOption" @changed =" codeChange" ></codemirror >
57
80
```
58
81
59
82
@@ -72,10 +95,16 @@ export default {
72
95
...
73
96
}
74
97
}
98
+ },
99
+ // if you use in vue2.X,parent component needs to explicitly emit an event instead of relying on implicit binding
100
+ methods: {
101
+ codeChange (newCode ) {
102
+ console .log (newCode)
103
+ this .code = newCode
104
+ }
75
105
}
76
106
}
77
107
78
-
79
108
// editorOption mode types:
80
109
81
110
// string mode
@@ -89,7 +118,7 @@ mode: {
89
118
```
90
119
91
120
``` html
92
- <!-- component config example 2 -->
121
+ <!-- component config example 2(Vue.js1.X) -->
93
122
<codemirror :code.sync =" css" :options =" { tabSize: 2, mode: 'css' }" ></codemirror >
94
123
```
95
124
@@ -106,11 +135,11 @@ data () {
106
135
107
136
[ Code example] ( https://github.com/surmon-china/vue-codemirror/tree/master/example )
108
137
109
- [ More codemirror configs ] ( http://codemirror.net/doc/manual.html#config )
138
+ [ Codemirror config APIs ] ( http://codemirror.net/doc/manual.html#config )
110
139
111
- [ More codemirror themes] ( http://codemirror.net/demo/theme.html )
140
+ [ Codemirror themes] ( http://codemirror.net/demo/theme.html )
112
141
113
- [ More codemirror language modes] ( http://codemirror.net/mode/ )
142
+ [ Codemirror language modes] ( http://codemirror.net/mode/ )
114
143
115
144
116
145
0 commit comments