Home > database >  how to create event on input in vuejs
how to create event on input in vuejs

Time:01-03

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:

  1. The input event is fired every time the value of the element changes.
  2. 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>

  • Related