Vue中的事件修饰符:
1.prevent:阻止默认事件
2.stop:组织事件冒泡
3.once:事件只触发一次
4.capture:使用事件的捕获模式
5.self:只有event.target是当前操作的元素才触发事件。
6.passive:事件的默认行为立即执行,无序等待事件回调执行完毕
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>事件修饰符</title>
<!-- 引入Vue -->
<script type="text/javascript" src="../js/vue.js"></script>
<style>
*{
margin-top: 20px;
}
.box1{
background-color:cornflowerblue;
height: 50px;
}
</style>
</head>
<body>
<!-- 准备好一个容器 -->
<div id="root">
<h2>欢迎来到{{name}}的博客学习</h2>
<!-- 阻止默认事件(常用) -->
<a href="https://xiaoyuan.blog.csdn.net/" @click.prevent="showInfo">点我进行跳转</a>
<!-- 阻止事件冒泡(常用) -->
<div class="box1" @click="showInfo">
<button @click.stop="showInfo">点我提示一下</button>
</div>
<!-- 事件只触发一次(常用) -->
<button @click.once="showInfo">点我提示一下</button>
</div>
</body>
<script type="text/javascript">
Vue.config.productionTip = false // 阻止 vue 在启动时生成生产提示
new Vue({
el:"#root",
data:{
name:"才疏学浅的小缘同学"
},
methods:{
showInfo(e){
alert('好好学习!')
}
}
})
</script>
</html>