Skip to content

Instantly share code, notes, and snippets.

@PKTseng
Created August 4, 2020 03:02
Show Gist options
  • Save PKTseng/f929f36855854c3c2e62da583678b65e to your computer and use it in GitHub Desktop.
Save PKTseng/f929f36855854c3c2e62da583678b65e to your computer and use it in GitHub Desktop.
偵聽按鍵事件keyCode
<div id="app">
<input v-model="input" @keydown="keydown">
<ul>
<li v-for="item in list">{{item}}</li>
</ul>
</div>
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