D
D
Denis Shpuganich2017-08-15 16:39:27
JavaScript
Denis Shpuganich, 2017-08-15 16:39:27

Why does vue call the click method on keypress event?

I don't understand why when you click on the input field of the Enter button, a click event occurs?
https://jsfiddle.net/h35y5jx7/2/

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Anton, 2017-08-15
@dyonis

Because by default, the first button has type = submit, and pressing enter causes the form to submit and calls the handler on the button as well. For complete happiness, you need to specify type = "button" for the button, and specify the prevent modifier for keydown
https://jsfiddle.net/2kcLjsb3/
try to remove the type from the button, and you will see the output four in the console.
the same if you remove .prevent from keydown

A
Alexander Aksentiev, 2017-08-15
@Sanasol

Because the form is "submitting"?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question