v-on可以监听多个方法吗?
https://www.cnblogs.com/gitByLegend/p/10835516.html
v-on可以监听多个方法
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
<template>
<div
class
=
"about"
>
<button @click=
"myclick('hello','world','你好世界',$event)"
>点我text</button>
<!-- v-on在vue2.x中测试,以下两种均可-->
<button v-on=
"{mouseenter: onEnter,mouseleave: onLeave}"
>鼠标进来1</button>
<button @mouseenter=
"onEnter"
@mouseleave=
"onLeave"
>鼠标进来2</button>
<!-- 一个事件绑定多个函数,按顺序执行,这里分隔函数可以用逗号也可以用分号-->
<button @click=
"a(),b()"
>点我ab</button>
<button @click=
"one()"
>点我onetwothree</button>
<!-- v-on修饰符 .stop .prevent .capture .self 以及指定按键.{keyCode|keyAlias} -->
<!-- 这里的.stop 和 .prevent也可以通过传入&event进行操作 -->
<!-- 全部按键别名有:enter tab
delete
esc space up down left right -->
<form @keyup.
delete
=
"onKeyup"
@submit.prevent=
"onSubmit"
>
<input type=
"text"
placeholder=
"在这里按delete"
>
<button type=
"submit"
>点我提交</button>
</form>
</div>
</template>
<script>
export
default
{
methods: {
//这里是es6对象里函数写法
a() {
console.log(
"a"
);
},
b() {
console.log(
"b"
);
},
one() {
console.log(
"one"
);
this
.two();
this
.three();
},
two() {
console.log(
"two"
);
},
three() {
console.log(
"three"
);
},
myclick(msg1, msg2, msg3, event) {
console.log(msg1 + msg2 +
"--"
+ msg3);
console.log(event);
},
onKeyup() {
console.log(
"you press 'delete'"
);
},
onSubmit() {
console.log(
"sumited"
);
},
onEnter() {
console.log(
"mouse enter"
);
},
onLeave() {
console.log(
"mouse leave"
);
}
},
};
</script>
|