C
C
codeZlo2018-09-11 15:35:57
Vue.js
codeZlo, 2018-09-11 15:35:57

How to create an event when the user has finished editing an input in vue.js?

Hello!

<input type="text" @input="some_function" v-model.number="some_variable">

In this code, the some_variable variable and the some_function function change and are executed exactly at the moment when the user changes the value in the field. And you need to catch the event and execute the function when the user has changed the value in the field and finished editing. Can you please tell me your options how to implement this?
Thanks in advance for your replies.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Proskurin, 2018-09-11
@codeZlo

Use @change instead of @input

A
Alexander Shapoval, 2018-09-11
@sanek_os9

Here you can see the sample code https://github.com/freelaxdeveloper/vue-hubculture...
Attention to

created: function () {
    // _.debounce — это функция из lodash, позволяющая ограничить
    // то, насколько часто может выполняться определённая операция.
    // В данном случае мы хотим ограничить частоту обращений к yesno.wtf/api,
    // дожидаясь завершения печати вопроса перед тем как послать ajax-запрос.
    // Чтобы узнать больше о функции _.debounce (и её родственнице _.throttle),
    // см. документацию: https://lodash.com/docs#debounce
    this.debouncedGetAnswer = _.debounce(this.getAnswer, 500)
  },

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question