0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Vue.js】キー修飾子で特定のキー押下時にイベントを発生させる

Posted at

はじめに

よくあるEnterキーで入力確定する方法を探していたら、キー修飾子があったので軽くまとめる。

キー修飾子とは

特定のキーを押された場合に、指定したイベントが発火する。
そして、v-on:clickなどのイベントにドット(.)でつなげることができる。

right

右クリック押下時にaddイベント発生。

HTML
<button @click.right="add">Add</button>

left

左クリック押下時にaddイベント発生。

HTML
<button @click.left="add">Add</button>

enter

inputの入力欄を選択しながら、エンターキー押下時にenterイベント発生。

HTML
 <input type="text" @input="setName" v-on:keyup.enter="enter" :value="name"> 

おわりに

他にも使ったキー修飾子が出てきたら、随時追加予定。

参考

https://qiita.com/Yudai_35_/items/02e6c08f9df43643b6f9
https://qiita.com/hidache/items/a3ac85c7e0cba4978cf8
Vueの勉強で活用中⇒https://www.udemy.com/course/vuejs-2-the-complete-guide/

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?