03 事件修饰符

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
     <!-- 1.导入vue的包 -->
     <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
</head>
<body>
        <div id="app">
             <!-- 使用.stop阻止冒泡行为 冒泡  从内到外触发事件  与捕获触发事件机制相反 -->
            <div  @click="handelFuncDiv">
                 <button @click.stop="handelFunc">阻止冒泡行为</button>
            </div>
              <!-- 使用.prevent阻止默认行为 -->
            <a @click.prevent href="http://www.baidu.com">百度一下</a>
             <!-- 使用.capture实现捕获触发的事件机制  从外到内触发事件 -->
             <div  @click.capture="handelFuncDiv">
                    <button @click="handelFunc">捕获事件</button>
               </div>
               <!-- 使用.self实现只能触发自身事件  只会阻止自身冒泡行为的触发 并不会真的阻止冒泡行为的触发 -->
               <div  @click.self="handelFuncDiv">
                    <button @click="handelFunc">自身触发机制</button>
               </div>
               <!-- 使用.once只能触发一次事件 -->
               <div  @click.once="handelFuncDiv">
                    <button @click="handelFunc">点击</button>
               </div>
            </div>
           
            <script>
                var vm=new Vue({
                    el:"#app",
                    data:{
                        msg:"我是跑马灯效果呀!",
                    },
                    methods:{
                      handelFunc(){
                          console.log("我是btn")
                      },
                      handelFuncDiv(){
                        console.log("我是div")
                      }
                    }
        
                })    
            </script>
</body>
</html>

修饰符

原文地址:https://www.cnblogs.com/zhupanpan/p/11843665.html