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>
复制代码

修饰符

posted @   zhupan  阅读(130)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术
点击右上角即可分享
微信分享提示