阻止冒泡 .stop
<body>
<div id="app">
<h2>{{num}}</h2>
<div @click="divclick">aaaaa
<button @click.stop="btnclick">按钮</button>
</div>
</div>
<script type="text/javascript" src="./js/vue.js"></script>
<script type="text/javascript">
const app = new Vue({
el: "#app",
data: {
num:1
},
methods:{
divclick(){
console.log('divclick');
},
btnclick(){
console.log('btnclick');
}
}
});
</script>
</body>
阻止默认事件.prevent
<body>
<div id="app">
<form action="baidu">
<input type="submit" name="" @click.prevent="submitClick">
</form>
</div>
<script type="text/javascript" src="./js/vue.js"></script>
<script type="text/javascript">
const app = new Vue({
el: "#app",
data: {
num:1
},
methods:{
submitClick(){
console.log('提交');
}
}
});
</script>
</body>
监听某个键盘的建帽.enter
<body>
<div id="app">
<input type="text" name="" value="" @keyup.enter="keyUp">
</div>
<script type="text/javascript" src="./js/vue.js"></script>
<script type="text/javascript">
const app = new Vue({
el: "#app",
data: {
num:1
},
methods:{
keyUp(){
console.log('keyUp');
}
}
});
</script>
</body>
监听某个事件只执行一次.once
<body>
<div id="app">
<button @click.once="btn">按钮2</button>
</div>
<script type="text/javascript" src="./js/vue.js"></script>
<script type="text/javascript">
const app = new Vue({
el: "#app",
data: {
num:1
},
methods:{
btn(){
console.log(111)
}
}
});
</script>
</body>