I have input on form text, I want to see the input in the log using what event key?
<input type="text" //event>
in this text for example I type
"seat"
then the console log appears
s
se
sea
seat
CodePudding user response:
The input
element fires 2 useful events when edited:
- The
input
event is fired every time the value of the element changes. - The
change
event fires when the value is committed, for example pressing the enter key, selecting a value from a dropdown list, etc.
In your case for a text
input element where you want every keypress, the input
event is what you need:
<input type="text" @input="inputEvent">
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event
CodePudding user response:
Maybe vue watcher is that where you looking for.
<template>
<div id="app">
<p>
<input v-model="value" placeholder="hi">
</p>
<p>value: {{ value }} </p>
</div>
</template>
<script>
export default {
data() {
return {
value: 'hey',
};
},
watch: {
value(val) {
console.log(val)
}
},
methods: {
}
};
</script>