.stop 阻止冒泡
<div id="app">
<!-- 事件后加 .stop 阻止冒泡 -->
<div @click="show('父')">父盒子
<div @click.stop="show('子')">子盒子</div>
</div>
</div>
<script>
var vm = new Vue({
el: '#app',
data:{
num: 0
},
methods:{
show:function(info){
console.log(info);
console.log(event.target.innerHTML);
}
}
})
</script>
.once 点击事件将只会触发一次
<div id="app">
<!-- 点击事件将只会触发一次 -->
<div @click.once="show">
<button>A</button>
<button>B</button>
<button>C</button>
</div>
</div>
<script>
var vm = new Vue({
el: '#app',
data:{
num: 0
},
methods:{
show:function(info){
console.log(event.target.innerHTML);
}
}
})
</script>
.prevent 阻止对象默认行为
<div id="app">
<a @click.prevent="handle()" href="http://baidu.com">去百度</a>
</div>
<script>
var vm = new Vue({
el: '#app',
data:{
num: 0
},
methods:{
handle:function(){
console.log('点了链接');
//阻止对象默认行为
//event.preventDefault()
}
}
})
</script>