Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On key press of Enter, click a button in vuejs

Tags:

vue.js

vuejs2

Here is my fiddle: DEMO

There is a button called "fb-send", which has to get clicked on key press on "enter" in the input field. How to achieve this?

<input @keyup.enter="" placeholder="Reply here" class="fb-comment-input" />
<i class="material-icons fb-button-right fb-send">&#x21E8;</i>

Any help would be much appreciated. Thank you.

like image 373
Inchara Raveendra Avatar asked Oct 09 '17 05:10

Inchara Raveendra


People also ask

How do you trigger a button on a enter key?

To trigger a click button on ENTER key, We can use any of the keyup(), keydown() and keypress() events of jQuery. keyup(): This event occurs when a keyboard key is released. The method either triggers the keyup event, or to run a function when a keyup event occurs.

What is the use of key in Vuejs?

key # The key special attribute is primarily used as a hint for Vue's virtual DOM algorithm to identify vnodes when diffing the new list of nodes against the old list. Without keys, Vue uses an algorithm that minimizes element movement and tries to patch/reuse elements of the same type in-place as much as possible.

What is the shorthand of V on click in VUE JS?

Vue has a convenient shorthand for v-on : the @ symbol. For example, @click is functionally equivalent to v-on:click .


2 Answers

You can also call method for fb_send directly on input field:

@keyup.enter="enterClicked()"
like image 110
pszkv Avatar answered Oct 21 '22 11:10

pszkv


<Input v-model="value1" size="large" placeholder="large size" @keyup.enter.native="search"></Input>
like image 29
panw3i Avatar answered Oct 21 '22 10:10

panw3i