Skip to content

Commit 0164b4a

Browse files
committed
fix: F-loat#86 value sync
1 parent 1d6afe5 commit 0164b4a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/index.vue

Lines changed: 8 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="modelVal"
6+
:value="value"
77
@input="handleInput($event.target.value)"
88
/>
99
</div>
@@ -49,7 +49,7 @@ export default {
4949
},
5050
data() {
5151
return {
52-
modelVal: '',
52+
isValueUpdateFromInner: false,
5353
};
5454
},
5555
mounted() {
@@ -100,7 +100,10 @@ export default {
100100
});
101101
},
102102
bindingEvents() {
103-
this.simplemde.codemirror.on('change', () => {
103+
this.simplemde.codemirror.on('change', (instance, changeObj) => {
104+
if (changeObj.origin === 'setValue') {
105+
return;
106+
}
104107
const val = this.simplemde.value();
105108
this.handleInput(val);
106109
});
@@ -133,10 +136,9 @@ export default {
133136
value(val) {
134137
if (this.isValueUpdateFromInner) {
135138
this.isValueUpdateFromInner = false;
136-
return;
139+
} else {
140+
this.simplemde.value(val);
137141
}
138-
this.simplemde.value(val);
139-
this.modelVal = val;
140142
},
141143
},
142144
};

0 commit comments

Comments
 (0)