<view class='title-info'>
<view bindtap='bindLabel' data-tip="0" class='item {{tip == 0 ? "on":""}}'>最新发布</view>
<view bindtap='bindLabel' data-tip="1" class='item {{tip == 1 ? "on":""}}'>最佳推荐<text class='top'>顶</text></view>
<view bindtap='bindLabel' data-tip="2" class='item {{tip == 2 ? "on":""}}'>最高人气</view>
<view bindtap='bindLabel' data-tip="3" class='item {{tip == 3 ? "on":""}}'>最近距离</view>
</view>
/**js
* 切换信息
*/
bindLabel:function(e){
var that = this;
var tip = e.currentTarget.dataset.tip;
this.setData({tip:tip});
wx.showLoading({ title: '加载中', mask: true });
page = 1;
that.setData({ list: [] });
render(that);
},
点击一次触发按钮 向服务器发送2次请求
第一次可能只是验证是否支持当前的请求类型是否支持,不返回结果的。
返回同样 的数据了
那你得把代码截图截全一点看看了,或者弄个代码片段
<!-- 信息 -->
<view class='info-wrap'>
<view class='title-info'>
<view bindtap='bindMenu' data-tip="0" class='item {{tip == 0 ? "on":""}}'>最新发布</view>
<view bindtap='bindMenu' data-tip="1" class='item {{tip == 1 ? "on":""}}'>最佳推荐<text class='top'>顶</text></view>
<view bindtap='bindMenu' data-tip="2" class='item {{tip == 2 ? "on":""}}'>最高人气</view>
<view bindtap='bindMenu' data-tip="3" class='item {{tip == 3 ? "on":""}}'>最近距离</view>
</view>
<view class='item-list'>
<block wx:for="{{list}}" wx:key="k">
<view bindtap='bindDetail' data-id="{{item.id}}" class='item'>
<view class='top-info'>
<view class='top-left'>
<view class='head-img'><image src='{{base_url}}{{item.logo}}'></image></view>
<view class='user-info'>
<view>
<view class='company-name'>{{item.company_name}}</view>
<view class='part'>{{item.department}}</view>
</view>
<view class='cate'>#{{item.cname}}#</view>
</view>
</view>
<view class='top-right'>
<view class='phone-top'>
<view catchtap='bindMakePhone' data-phone="{{item.phone}}" class='phone'><text class='iconfont icon-dianhua3'></text>拨打电话</view>
<view wx:if="{{item.is_top == 1}}" class='top'>顶</view>
</view>
</view>
</view>
<view class='info'>{{item.info}} </view>
<view class='img-wrap'>
<block wx:for="{{item.img_list}}" wx:for-item="itemName">
<view wx:if="{{index < 4}}"><image src='{{base_url}}{{itemName.img_url}}'></image></view>
</block>
</view>
<view class='address-wrap'>
<view class='address'><text class='iconfont icon-tubiaozhizuomoban'></text>{{item.address}}</view>
<view>{{item.distance}}km</view>
</view>
<view class='date'>{{item.add_time}}</view>
</view>
</block>
</view>
</view>
js
var render = function (that) {
wx.request({
url: base_url + 'index.php?c=wxApp&a=pagingInfoList',
data: {
type:0,
tip: that.data.tip,
keyword: keyword,
city: that.data.city,
latitude: that.data.myLatitude,
longitude: that.data.myLongitude,
pageIndex: page,
pageSize: pageSize,
},
method: 'GET',
success: function (res) {
var data = res.data.data;
var dataList = data.dataList;
var list = that.data.list;
allPages = data.pageInfo.all_pages;
for (var i = 0; i < dataList.length; i++) {
list.push(dataList[i]);
}
console.log(dataList, 888)
that.setData({ list: list });
page++;
},
complete: function () {
wx.hideLoading()
}
})
};
Page({
/**
* 页面的初始数据
*/
data: {
tip:0,
base_url: base_url,
tipShow: true,
},
/**
* 切换信息
*/
bindMenu:function(e){
var that = this;
var tip = e.currentTarget.dataset.tip;
wx.showLoading({ title: '加载中', mask: true });
page = 1;
that.setData({ list: [], tip: tip });
render(that);
},
})
加一个状态锁吧,点击切换的时候锁定下状态,请求成功后解除。这样就不会重复请求了
同时请求 我都试了 解决不掉
找不到原因啊 很急
代码片段无法使用,短时间内没看出大的问题,有可能是点击穿透的问题,你试试不调用request看下bindMenu的执行情况