-
Notifications
You must be signed in to change notification settings - Fork 144
/
17.keyCode.html
40 lines (40 loc) · 964 Bytes
/
17.keyCode.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="bootstrap.css">
</head>
<body>
<div id="app">
<input type="text" v-on:keyup.b="tap | debounce 2000" v-model="name">
<!--//根据我们数组的内容进行重复-->
<div v-for="l in list" track-by="$index">
{{l}} <button @click="del(l)">x</button>
</div>
</div>
<script src="vue.js"></script>
<script>
//设置一个键盘按键 自定义b事件修饰
Vue.directive('on').keyCodes.b= 66;
var vm = new Vue({
el:'#app',
data:{
name:'',
list:[],
},
methods:{
tap: function () {
if(this.name){
this.list.push(this.name);
}
this.name = '';
},
del: function (l) {
this.list.$remove(l);
}
}
});
</script>
</body>
</html>