.stop 停止事件冒泡
.prevent 阻止事件默认行为
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="demo">
<h2>绑定监听</h2>
<button @click="test1">test1</button>
<button @click="test2('a')">test1</button>
<button @click="test3($event)">test1</button>
<button @click="test4(123,$event)">test1</button>
<h2>事件修饰符</h2>
<div style="width: 200px;height: 200px;background-color: red" @click="test5">
<div style="width: 100px;height: 100px;background-color: blue" @click.stop="test6"></div>
</div>
<a href="www.baidu.com" @click.prevent="test7">去百度</a>
<h2>按键修饰符</h2>
<input type="text" @keyup.13="test8">
<input type="text" @keyup.enter="test8">
</div>
</body>
<script src="../js/vue.js"></script>
<script>
new Vue({
el:'#demo',
data:{
test1(){
alert('test1');
},
test2(msg){
alert(msg);
},
test3(event){
alert(event.target.innerHTML);
},
test4(number,event){
alert(number + '---' + event.target.innerHTML);
},
test5(){
alert('out');
},
test6(event){
event.stopPropagation();//阻止事件冒泡
alert('inner');
},
test7(event){
event.preventDefault();//阻止事件的默认行为
alert('点击');
},
test8(event){
alert(event.target.value);
}
}
})
</script>
</html>
网友评论