您的位置:首页 > 移动开发 > 微信开发

小程序实现选项卡效果代码

2018-03-02 09:55 197 查看
//test.wxml
<view class='h_ctr4 bc_white'>
<view bindtap='xuan' data-num="1" data-id='zuijin' class="{{_num == 1 ? 'isxuan':'xuan'}}">全部</view>
<view bindtap='xuan' data-num="2" data-id='zuigao' class="{{_num == 2 ? 'isxuan':'xuan'}}">未使用</view>
<view bindtap='xuan' data-num="3" data-id='quanbu' class="{{_num == 3 ? 'isxuan':'xuan'}}">已使用</view>
</view>


//test.wxss
/*选项卡*/
.h_ctr4 {
width: 100%;
height: 75rpx;
line-height: 75rpx;
font-size: 30rpx;
margin-top: 0rpx;
display: flex;
}
.xuan{
width: 250rpx;
text-align: center;
color: #333333;
}
.isxuan{
text-align: center;
width: 250rpx;
border-bottom: 10rpx solid #b4282d;
color: #b4282d;
}


//test.js
Page({

/**
* 页面的初始数据
*/
data: {
_num: 1, //这是点击选项卡参数,不是接口不需要传值

},
//点击切换距离、销量、全部店铺
xuan: function (e) {
var that = this;
this.setData({
_num: e.target.dataset.num
})
var id = e.currentTarget.dataset.id;
if (id == "zuijin") {
wx.request({
// url: 'https://ceshi23.acorntimes.com/a/gongsi_zuijin.json',
// url: 'http://192.168.199.181/a/gongsi_zuijin.json',
url: rootDocment + '/a/gongsi_zuijin.json',
data: { id: id },
method: 'POST',
header: {},
success: function (res) {
that.setData({
shops: res.data.data.shops
});
}
})
}
if (id == "zuigao") {
wx.request({
// url: 'https://ceshi23.acorntimes.com/a/gongsi_zuijin.json',
// url: 'http://192.168.199.181/a/gongsi_zuijin.json',
url: rootDocment + '/a/gongsi_zuigao.json',
data: { id: id },
method: 'POST',
header: {},
success: function (res) {
that.setData({
shops: res.data.data.shops
});
}
})
}
if (id == "quanbu") {
wx.request({
// url: 'https://ceshi23.acorntimes.com/a/gongsi_zuijin.json',
// url: 'http://192.168.199.181/a/gongsi_zuijin.json',
url: rootDocment + '/a/gongsi_quanbu.json',
data: { id: id },
method: 'POST',
header: {},
success: function (res) {
that.setData({
shops: res.data.data.shops
});
}
})
}
},
})
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: