Created
August 4, 2020 05:09
-
-
Save PKTseng/0edb77b81a406a1bfaa58a7b22cc6412 to your computer and use it in GitHub Desktop.
偵聽按鍵事件keyCode簡短
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="app"> | |
<input v-model="input" @keydown.enter="keydown"> | |
<ul> | |
<li v-for="item in list">{{item}}</li> | |
</ul> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new Vue({ | |
el:"#app", | |
data:{ | |
input:'', | |
list:[] | |
}, | |
methods:{ | |
keydown(){ | |
this.list.push(this.input); | |
this.input=''; | |
} | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment