@@ -29,6 +29,9 @@ export default {
29
29
configs .element = configs .element || this .$el .firstChild
30
30
configs .initialValue = configs .initialValue || this .value
31
31
32
+ // 实例化编辑器
33
+ this .simplemde = new SimpleMDE (configs)
34
+
32
35
// 开启代码高亮
33
36
if (configs .renderingConfig && configs .renderingConfig .codeSyntaxHighlighting ) {
34
37
require .ensure ([], () => {
@@ -38,26 +41,30 @@ export default {
38
41
}, ' highlight' )
39
42
}
40
43
41
- // 实例化编辑器
42
- this .simplemde = new SimpleMDE (configs)
43
-
44
44
// 添加自定义 previewClass
45
- this .addPreviewClass ()
45
+ var _class = this .previewClass || ' '
46
+ if (configs .renderingConfig && configs .renderingConfig .codeSyntaxHighlighting ) {
47
+ _class += ' hljs'
48
+ }
49
+ this .addPreviewClass (_class)
46
50
47
51
// 绑定输入事件
48
52
this .simplemde .codemirror .on (' change' , () => {
49
53
this .$emit (' input' , this .simplemde .value ())
50
54
})
51
55
},
52
- addPreviewClass () {
53
- var _class = (this .configs .renderingConfig && this .configs .renderingConfig .codeSyntaxHighlighting ) ? (this .previewClass || ' ' ) + ' hljs' : (this .previewClass || ' ' )
56
+ addPreviewClass (_class ) {
54
57
var wrapper = this .simplemde .codemirror .getWrapperElement ()
55
58
var preview = document .createElement (' div' )
56
59
wrapper .nextSibling .className += ' ' + _class
57
60
preview .className = ' editor-preview ' + _class
58
61
wrapper .appendChild (preview)
59
62
}
60
63
},
64
+ destroyed () {
65
+ this .simplemde .toTextArea ()
66
+ this .simplemde = null
67
+ },
61
68
watch: {
62
69
value (val ) {
63
70
if (val === this .simplemde .value ()) return
0 commit comments