Skip to content
Advertisement

Vue.js: Calling function on change

I’m building a component in Vue.js. I have an input on the page where the user can request a certain credit amount. Currently, I’m trying to make a function that will log the input amount to the console, as I type it in. (Eventually, I’m going to show/hide the requested documents based on the user input. I don’t want them to have to click a submit button.)

The code below logs it when I tab/click out of the input field. Here’s my component.vue:

JavaScript

If I change methods to computed, it works – but I get an error saying Invalid handler for event: change every time it logs the value.

Advertisement

Answer

Use the input event.

JavaScript

change only fires when the element loses focus for input elements. input fires each time the text changes.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement