F
F
fostsinger2018-07-24 12:53:00
Vue.js
fostsinger, 2018-07-24 12:53:00

Entering only numbers in the field and one at a time Vue?

It is necessary to allow only numbers to be entered in each field, and one at a time.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-06-21
@fostsinger

<input @input="onInput">

onInput({ target }) {
  const
    val = target.value,
    newVal = `${Math.min(9, Math.max(0, val.slice(-1) | 0))}`;

  if (val !== newVal) {
    target.value = newVal;
    target.dispatchEvent(new Event('input'));
  }
},

https://jsfiddle.net/0gocpeLh/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question