微信小程序中用swiper标签时内容显示不全解决方法:
第一,先在swiper标签中的view标签改成scroll-view标签。(不然后面重新获得长度也不能拉到底部显示全部内容。当然,内容较少的页面就可以不用改)
<swiper current="{{currentTab}}" >
<swiper-item>
<scroll-view scroll-y="{{true}}" >
<!--大堆内容-->
</scroll-view>
</swiper-item>
<swiper-item>
<view class="litleWord">
<!--很少内容,不用改标签-->
</view>
</swiper-item>
</swiper>
第二步,动态获取窗口高度应用到swiper和所有的scroll-view标签。事实上,内容显示不全就是因为获取的高度过小。
<!--主文件html中代码:-->
<swiper current="{{currentTab}}" style="height:{{navHeight}}px">
<swiper-item>
<scroll-view scroll-y="{{true}}" style="height:{{navHeight}}px">
<!--大堆内容-->
</scroll-view>
</swiper-item>
<swiper-item>
<view class="litleWord">
<!--很少内容,不用改标签-->
</view>
</swiper-item>
</swiper>
/*主文件js代码*/
onLoad: function () {
this.setData({
navHeight:app.globalData.navHeight,
})
},
/*app.js中的代码*/
onLaunch: function () {
wx.getSystemInfo({
success: res => {
this.globalData.navHeight = res.windowHeight; //动态获得窗口高度。当然,别忘了要在app.js中设置全局变量navHeight,以及上面主文件的js文件也是同理。
console.log(this.globalData.navHeight, 'this.globalData.navHeight')
}, fail(err) {
console.log(err);
}
})
},
然后就可以发现显示正常了~
若仍显示不全,则试着在主文件的js文件中的onload函数里把navHeight的值再自加100px。
代码如上,欢迎讨论。