3
3
<textarea
4
4
class =" vue-simplemde-textarea"
5
5
:name =" name"
6
- :value =" value "
6
+ :value =" modelValue "
7
7
@input =" handleInput($event.target.value)"
8
8
/>
9
9
</div >
@@ -15,8 +15,13 @@ import marked from 'marked';
15
15
16
16
export default {
17
17
name: ' vue-simplemde' ,
18
+ model: {
19
+ prop: ' modelValue' ,
20
+ event : ' update:modelValue' ,
21
+ },
18
22
props: {
19
23
value: String ,
24
+ modelValue: String ,
20
25
name: String ,
21
26
previewClass: String ,
22
27
autoinit: {
@@ -65,14 +70,14 @@ export default {
65
70
initialize () {
66
71
const configs = Object .assign ({
67
72
element: this .$el .firstElementChild ,
68
- initialValue: this .value ,
73
+ initialValue: this .modelValue || this . value ,
69
74
previewRender: this .previewRender ,
70
75
renderingConfig: {},
71
76
}, this .configs );
72
77
73
- // 同步 value 和 initialValue 的值
78
+ // 同步 modelValue 和 initialValue 的值
74
79
if (configs .initialValue ) {
75
- this .$emit (' input ' , configs .initialValue );
80
+ this .$emit (' update:modelValue ' , configs .initialValue );
76
81
}
77
82
78
83
// 判断是否开启代码高亮
@@ -121,7 +126,7 @@ export default {
121
126
},
122
127
handleInput (val ) {
123
128
this .isValueUpdateFromInner = true ;
124
- this .$emit (' input ' , val);
129
+ this .$emit (' update:modelValue ' , val);
125
130
},
126
131
handleBlur (val ) {
127
132
this .isValueUpdateFromInner = true ;
@@ -132,7 +137,7 @@ export default {
132
137
this .simplemde = null ;
133
138
},
134
139
watch: {
135
- value (val ) {
140
+ modelValue (val ) {
136
141
if (this .isValueUpdateFromInner ) {
137
142
this .isValueUpdateFromInner = false ;
138
143
} else {
0 commit comments