button如何阻止冒泡?
发布于 6 年前 作者 plai 6641 次浏览 来自 问答

bind和catch可以处理冒泡,但比如调起分享的时候要必须用button open-type="share"完成,不能绑定事件,这种情况如何阻止冒泡?

4 回复

 open-type="share"也可以catchtap的~~

也会执行的。不冲突

<button open-type="share" catchtap="csss">转发给好友</button>
  csss:function (e) {
        console.log("e",e);
   }

<view bindtap=“func1”>
  <button open-type=“share” catchtap=“func2”>分享</button>
</view>

func1(e) {   console.log(‘view’) }, func2(e) {   console.log(‘button’) } 只会触发func2,不会触发func1,因为func2是catch,已阻止冒泡到func1 分享功能不受影响,其实func2定不定义都没事

若认为该回答有用,给回答者点个[ 有用 ],让答案帮助更多的人

考虑一下,阻止冒泡肯定是不符合分享的条件?不符合条件的话也是个状态,状态是否用view 是的时候用button,class一致。在其他的业务逻辑里控制分享状态。

给button的catchtap绑定一个空方法就可以了

回到顶部