Skip to content

Instantly share code, notes, and snippets.

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