Reputation: 623
Code:
<input type = "number" min="10" max="90" value="50" v-model="preview_width"/>
My website changes width of 2 components depending on "preview_width value". When I change value in input, website moves and doesn't let user enter correct value in friendly way. And my question is: How to edit "preview_value" AFTER user press "Enter", or after he stop targeting this input?
Upvotes: 3
Views: 6209
Reputation: 72
v-model
has a .lazy
modifier, which will sync the data after change events:
<input type = "number" min="10" max="90" value="50" v-model.lazy="preview_width"/>
You can read the documentation here: https://v2.vuejs.org/v2/guide/forms.html#lazy
Upvotes: 5
Reputation: 278
You can use lodash debounce method, which will delay triggering of the method to update width.
<input v-on:input="onChangePreviewWidth">
...
methods: {
onChangePreviewWidth: _.debounce(function (e) {
this.preview_width = e.target.value;
}, 500)
}
...
Upvotes: 1
Reputation: 4656
You could use lazy
to update the v-model
only on change.
<input type = "number" min="10" max="90" value="50" v-model.lazy="preview_width"/>
or
<input type = "number" min="10" max="90" value="50" v-model="preview_width" lazy/>
Here is the doc: https://v1.vuejs.org/guide/forms.html#lazy
Upvotes: 2