Skip to content

Commit 7982afc

Browse files
committed
feat: support vue@3
1 parent 4622a65 commit 7982afc

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/index.vue

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<textarea
44
class="vue-simplemde-textarea"
55
:name="name"
6-
:value="value"
6+
:value="modelValue"
77
@input="handleInput($event.target.value)"
88
/>
99
</div>
@@ -15,8 +15,13 @@ import marked from 'marked';
1515
1616
export default {
1717
name: 'vue-simplemde',
18+
model: {
19+
prop: 'modelValue',
20+
event: 'update:modelValue',
21+
},
1822
props: {
1923
value: String,
24+
modelValue: String,
2025
name: String,
2126
previewClass: String,
2227
autoinit: {
@@ -65,14 +70,14 @@ export default {
6570
initialize() {
6671
const configs = Object.assign({
6772
element: this.$el.firstElementChild,
68-
initialValue: this.value,
73+
initialValue: this.modelValue || this.value,
6974
previewRender: this.previewRender,
7075
renderingConfig: {},
7176
}, this.configs);
7277
73-
// 同步 value 和 initialValue 的值
78+
// 同步 modelValue 和 initialValue 的值
7479
if (configs.initialValue) {
75-
this.$emit('input', configs.initialValue);
80+
this.$emit('update:modelValue', configs.initialValue);
7681
}
7782
7883
// 判断是否开启代码高亮
@@ -121,7 +126,7 @@ export default {
121126
},
122127
handleInput(val) {
123128
this.isValueUpdateFromInner = true;
124-
this.$emit('input', val);
129+
this.$emit('update:modelValue', val);
125130
},
126131
handleBlur(val) {
127132
this.isValueUpdateFromInner = true;
@@ -132,7 +137,7 @@ export default {
132137
this.simplemde = null;
133138
},
134139
watch: {
135-
value(val) {
140+
modelValue(val) {
136141
if (this.isValueUpdateFromInner) {
137142
this.isValueUpdateFromInner = false;
138143
} else {

0 commit comments

Comments
 (0)