v-on能夠監聽多個方法嗎?

原文地址javascript


v-on能夠監聽多個方法html

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

  

相關文章
相關標籤/搜索