Created
August 4, 2020 03:02
-
-
Save PKTseng/f929f36855854c3c2e62da583678b65e 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="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(evt){ | |
// console.log(evt.keyCode); | |
if(evt.keyCode === 13){ | |
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