最近在项目遇到swiper高度不能自适应,导致swiper-item 里面的内容过多时只能显示一部分,最终解决方案:
<swiper current="{{currentTab}}" style="height: {{clientHeight?clientHeight+'px':'auto'}}">
<swiper-item>
<scroll-view scroll-y="{{true}}" style="height: {{clientHeight?clientHeight+'px':'auto'}}" bindscrolltolower="scrollbot">
内容放在这
</scroll-view>
</swiper-item>
</swiper>
在样式中加入
swiper-item {
overflow: scroll;
}
最后在后台onLoad中动态获得屏幕可视区域高度clientHeight即可
onLoad: function () {
var that = this
wx.getSystemInfo({
success: function (res) {
that.setData({
clientHeight: res.windowHeight-177
});
}
})
}