最近在做一个微信小程序项目,遇到了一个棘手的问题:swpier做选项卡切换页面,自定义的tabbar不可以用,即tabbar无法响应点击事件,而且swpier的高度不能自适应,查了很多资料后,最后是这样解决的:
1、先获取设备可视窗口的高度
onLoad: function (options) {
var that = this;
//获取设备可视窗口高度
wx.getSystemInfo({
success: function (res) {
that.setData({
clientHeight: res.windowHeight - 40//这里的40是我自定义tabbar的高度
});
}
})
},
2、设置swpier的高度,注意swiper的高度不要设置为固定值,否则无法做到自适应。
<swiper style="height:{
{clientHeight?clientHeight+'px':'auto'}}" current="{
{currentTab}}" duration="200" bindchange="swiperChange">
3、在swiper-item中嵌套一个scroll-view,并设置scroll-view的属性
<swiper-item >
<scroll-view scroll-y="{
{true}}" style="height: {
{clientHeight?