On Android the length of v-model is returning 0 on keyup unless its a number or the space bar key. Does anyone know why that is and how to make it fire the keyup event no matter what key it is and get the length? Here is a cleaned up version of what I have:
<template>
<div class="typeahead">
<input
v-model="query"
v-on:keyup="suggestTerms"
>
</div>
</template>
<script>
export default {
data () {
return {
query: '',
}
},
methods: {
suggestTerms () {
console.log('query length = ' + this.query.length);
}
}
}
</script>
P.S. This works on every browser and device except Android.
It works on computers, but not on mobile..
lazy. By default, v-model syncs with the state of the Vue instance (data properties) on every input event - which means every single time the value of our input changes. The . lazy modifier changes our v-model so it only syncs after change events. The change event is triggered when a change is commited.
The keyup event is fired when a key is released. The keydown and keyup events provide a code indicating which key is pressed, while keypress indicates which character was entered.
Although you can replace jQuery with Vue, you'll need to change your mindset about how to solve Web development problems.
There have been instances when v-model didn't update on mobile in some cases. Issue on Forum (current), Another from Forum
You can also code the v-model explicitly, it works in both android and pc.
function callMe(){
var vm = new Vue({
el : '#root',
data : {query : ''},
methods: {
suggestTerms () {
console.log('query length = ' + this.query.length);
}
}
})
}
callMe();
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<div id='root'>
<h3>Decomposed</h3>
<div>
<input type='text' :value='query' @input='evt=>query=evt.target.value' v-on:keyup="suggestTerms">
<b>{{query}}({{query.length}})</b>
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With