【VUE事件修饰符self capture stop】

VUE事件修饰符self capture stop

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="js/vue.js"></script>
  <script src="js/axios.min.js"></script>
  <style>
    .d1{
      width: 400px;height: 400px;
      background-color: aqua;
    }
    .d2{
      width: 300px;height: 300px;
      background-color:red;
    }
    .d3{
      width: 200px;height: 200px;
      background-color:rgb(208, 255, 0);
    }
    .d4{
      width: 100px;height: 100px;
      background-color:rgb(25, 167, 25);
    }
  </style>
</head>
<body>
  <div id="app">
    <!-- self只有作用于他自身才会执行,没主动触发跳过事件不执行 -->
    <div class="d1" @click.self="alert(1)">
      div1
      <div class="d2"  @click.capture="alert(2)">
        div2
        <!-- 注意正常的冒泡是先执行被点击的目标对象,再从目标对象位置开始向外冒泡执行 -->
        <!-- 所以如果点击2是不会执行内层的capture -->
        <div class="d3"  @click.capture="alert(3)">
          div3
          <!-- 点击capture由外向内执行capture,点击4会先执行34
          然而点击3是不会执行4-->
          <!-- 此外stop是一道屏障,只会执行到该屏障为止,屏障后续不执行 -->
          <!-- capture优先于stop执行,从外向内执行 -->
          <div class="d4"  @click.stop="alert(4)">div4</div>
        </div>
      </div>
    </div>
  </div>
  <script>
    new Vue({
      el:"#app",
      data:{
      },
     methods: {
       alert(i){
         alert(i);
       }
     },
    })
  </script>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值