Vue.js クリックイベント時にENTERキーイベントも取得する

Vue.jsで、クリックイベント時にENTERキーイベントも取得するサンプルコードを記述してます。 「vue3」を使用してます。
環境
- OS windows10 pro 64bit
- Vue.js 3.0.0
- Apache 2.4.43
- ブラウザ chrome 92.0.4515.107
クリックイベント時にENTERキーイベントも取得する
クリックイベント時に「ENTERキー」イベントも取得するには、「v-on:click.enter」を使用します。
「v-on:click.enter」は、「@click.enter」と省略できます。
以下は、「実行」ボタンをクリックした後に要素上で「 ENTERキー 」を押下した際に、変数「count」が1ずつ増加するサンプルコードとなります。
※「vue3」は「cdn版」、デザインは「semantic-ui」を使用してます。
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>mebeeサンプル</title>
<!-- semantic.css -->
<link rel="stylesheet" type="text/css"
href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css">
<script src="https://unpkg.com/vue@next"></script>
</head>
<style>
body>.grid {
height: 100%;
}
.fields {
margin-top: 5px;
}
</style>
<body>
<div id="app" class="ui middle aligned center aligned grid">
<div class="column">
<h2 class="ui gray header">count = {{count}}</h2>
<div class="ui stackable fields">
<button v-on:click.enter="foo" class="ui violet button">実行</button>
</div>
</div>
</div>
<script>
const hoge = {
data() {
return {
count: 0
}
},
methods: {
foo: function () {
this.count++
}
}
}
Vue.createApp(hoge).mount('#app')
</script>
</body>
</html>
実行されていることが確認できます。

-
前の記事
python PySimpleGUIでtreeのテキストのカラーを設定する 2022.02.23
-
次の記事
C# 配列またはリストのインデックス番号を指定して値を取得する 2022.02.23
コメントを書く