老师帮我看看 找不到函数 谢谢
来源:4-7 WXS 实现手指滑动监听切换标签(下)

weibo_被看穿了吗z_0
2021-09-10
touchMove.wxs
var touchstartX
// 滑动开始
function handlestart(e) {
touchstartX = e.changedTouches[0].clientX //开始时的位置
}
// 滑动结束
function handlend(e, ownerInstance) {
touchendX = e.changedTouches[0].clientX //结束时的位置
var movecout = touchendX - touchstartX //负数向左滑动 反之..
// 判断滑动方向 -1后退(向右) 0 不动 1 前进
var movenum = 0
if (movecout < 0 && movecout < -70) { //前进
movenum = 1
}
if (movecout > 0 && movecout > 70) { //后退
movenum = -1
}
if (movenum !== 0) {
// 调用引用该wxs的组件的方法
ownerInstance.callMethod('handlendmove', {
movenum: movenum
})
}
}
module.exports = {
handlestart: handlestart,
handlend: handlend
}
/////////////////////////////////////////////////////////
tabs>index.js
Component({
options: {
multipleSlots: true
},
properties: {
tabs: {
type: Array,
value: []
}
},
data: {
tabnum: 0,
},
methods: {
handeltab: function (e) {
const index = e.currentTarget.dataset.index
this.setData({
tabnum: index
})
this.triggerEvent('change', {index})
},
// wxs滑动
handlendmove:function(e){
console.log(e)
}
}
})
///////////////////////////////////////////
index.wxml
<wxs src="../../common/wxs/touchMove.wxs" module="touch"></wxs>
<view class="container">
<view class="tabs">
<view class="tab-item" wx:for="{{tabs}}" wx:key="index">
<view class="tab-tabl {{tabnum === index?'active-tab':''}}" wx:key="index" data-index="{{index}}"
bindtap="handeltab">{{item}}</view>
<view wx:if="{{tabnum === index}}" class="divider"></view>
</view>
</view>
<!-- 滑块 -->
<view>
<slot name="category"></slot>
</view>
<!-- 内容 -->
<view bind:touchstart="{{touch.handlestart}} " bind:touchend="{{touch.handlend}} ">
<slot name="panel"></slot>
</view>
</view>
写回答
2回答
-
课程群里处理了,问题是因为bind:touchstart="{{touch.handlestart}} " 这里}}和”之间多了个空格,这个问题比较坑,留个记录提醒其他同学。
012021-09-10 -
沁尘
2021-09-10
你 tabs.js里的handlendmove方法写在了handeltab里面,WXS 找不到这个handlendmove。
00
相似问题