admin管理员组文章数量:1359268
I have a Vue ponent very similar to the example reported here:
watch: {
query(n, o) {
// Display loading animation
this.loading = true;
// Search debounced
this.debouncedSearchUser();
}
},
Where query
is a String variable bound to a text input using v-model
:
data() {
return {
query: "",
loading: false,
results: []
}
},
Everything works fine, except on chrome for android where the watch trigger is only fired once (when query
changes from ""
to whatever I write).
Any idea?
EDIT:
The problem seems to be related with the v-model
directive: I made some experiments with native javascript events and the value of v-model is not updated until I unfocus the input. If anyone's interested here is the binding:
<input v-model="query" class="input-text-light pad-s-m f-m"/>
Any way to get around this using watch and v-model
?
I have a Vue ponent very similar to the example reported here:
watch: {
query(n, o) {
// Display loading animation
this.loading = true;
// Search debounced
this.debouncedSearchUser();
}
},
Where query
is a String variable bound to a text input using v-model
:
data() {
return {
query: "",
loading: false,
results: []
}
},
Everything works fine, except on chrome for android where the watch trigger is only fired once (when query
changes from ""
to whatever I write).
Any idea?
EDIT:
The problem seems to be related with the v-model
directive: I made some experiments with native javascript events and the value of v-model is not updated until I unfocus the input. If anyone's interested here is the binding:
<input v-model="query" class="input-text-light pad-s-m f-m"/>
Any way to get around this using watch and v-model
?
- It works on the chrome desktop version? – choasia Commented Jun 28, 2018 at 9:24
-
Yes, on desktop it works perfectly. Anyway, I made some experiments (using native events such as 'keydown') and the problem is not the watch trigger but the
v-model
directive not updatingquery
value. I'm updating the question – Sneppy Commented Jun 28, 2018 at 9:36 - The most recent update to Chrome desktop is now in the same boat as the Android version. Unfortunate this happened. I'll have to abandon the v-model if I want to watch that property :( – Craig Commented Sep 3, 2018 at 15:50
1 Answer
Reset to default 7It seems to be a bug for v-model
. Since v-model
is just a syntactic sugar.
I think you can use the code below to make it work.
<input v-bind:value="query" v-on:input="query = $event.target.value"></input>
本文标签: javascriptVue watch on vmodel property only fired onceStack Overflow
版权声明:本文标题:javascript - Vue watch on v-model property only fired once - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744081406a2587710.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论