阻止冒泡
<div style="width: 200px;height: 200px;background: red" @click="test5">
<div style="width: 100px;height: 100px;background: blue" @click.stop="test6"></div>
</div>
test5() {
alert("点击了外面")
},
test6(){
alert("点击了里面")
},
阻止默认事件
<a href="http://www.baidu.com" @click.prevent= "test7">去百度</a>
test7(){
alert("去百度")
},
还有一种方法,比较原始
<form v-on:submit="onSubmit($event)">
<input type="text">
<button type="submit">提交</button>
</form>
onSubmit: function(e){
e.preventDefault();
console.log("submitted")
},
阻止submit默认提交表单事件
<form action="/XXX" @submit.prevent="handleSubmit"></form>
methods: {
handleSubmit(){
console.log(this.username + ' ' + this.pwd)
}
}