Stop applet from bubbling

1. Direct use method: catchtouchmove = "preventD"

< view class = "selector-bj {{isTapSelector ? '' : 'is-focus-selector' }}"
wx:if = "{{selectorBj}}" bindtap = 'tapSeleBj' catchtouchmove = "preventD"></ view >

//Prevent clicks from penetrating the background layer
preventD: function (){

},


2. Use catch instead of bind

bindEvent binding does not prevent bubbling events from bubbling upwards, catchevent binding prevents bubbling events from bubbling upwards.

As in the example below, clicking on the inner view will call handleTap3and handleTap2(because the tap event will bubble up to the middle view, and the middle view prevents the tap event from bubbling and is no longer passed to the parent node), clicking on the middle view will trigger handleTap2, click outer view will fire handleTap1.

<view id="outer" bindtap="handleTap1">
  outer view
  <view id="middle" catchtap="handleTap2">
    middle view
    <view id="inner" bindtap="handleTap3">
      inner view
    </view>
  </view>
</view>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325983579&siteId=291194637