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>
|