先看代码案例:
<!--components/date/date.wxml-->
<view class="dragComponent" id="dragComponentId" style="top:{{buttonTop}}px;left:{{buttonLeft}}px;" catchtouchstart = "_touchstart" catchtouchmove = "_touchmove" catchtouchend = "_touchend">
<view class="menuIconTop">
<navigator url='../home/home' hover-class='none' open-type='navigate'>
<text class="iconfont icon-shouye color_white font35"></text>
</navigator>
</view>
<view class="menuIcon">
<navigator url='../userFanProblem/userFanProblem' hover-class='none' open-type='navigate'>
<text class="iconfont icon-fankui color_white font35"></text>
</navigator>
</view>
<slot></slot>
</view>
这是我封装的拖拽组件,wxml代码我是这样写的,结果运行之后,发现在页面中,拖拽组件可以拖拽,但是组件子元素的跳转链接,却无法正常执行。
经过一番查找之后,原来是catchtouchstart事件的原因:
改正之后的代码:
<!--components/date/date.wxml-->
<view class="dragComponent" id="dragComponentId" style="top:{{buttonTop}}px;left:{{buttonLeft}}px;" bindtouchstart = "_touchstart" catchtouchmove = "_touchmove" bindtouchend = "_touchend">
<view class="menuIconTop">
<navigator url='../home/home' hover-class='none' open-type='navigate'>
<text class="iconfont icon-shouye color_white font35"></text>
</navigator>
</view>
<view class="menuIcon">
<navigator url='../userFanProblem/userFanProblem' hover-class='none' open-type='navigate'>
<text class="iconfont icon-fankui color_white font35"></text>
</navigator>
</view>
<slot></slot>
</view>
总结:
如果你是想要让父元素移动的时候,阻止页面同时滚动,并且想要子元素的点击事件正常工作的话。这样设置:
【父元素】bind:touchstart、catch:touchmove、bind:touchend
【子元素】bindtap、catchtap均可