由于官方給了 swiper 固定高度150,且 swiper-item 都是 absolute 定位,所以實(shí)際應(yīng)用中經(jīng)常會(huì)碰到問(wèn)題,在此記錄一下修改方式。
<mp-tabs tabs="{{tabs}}" activeTab="{{activeTab}}" swiperClass="weui-tabs-swiper" bindtabclick="onTabCLick" bindchange="onChange" activeClass="tab-bar-title__selected" swiperStyle="height: {{tabSwiperHeight}}px" > <block wx:for="{{tabs}}" wx:for-item="tab" wx:for-index="index" wx:key="index"> <view class="tab-content tab-content-{{index}}" slot="tab-content-{{index}}" > {{tab.title}} </view> </block> </mp-tabs> Page({ data: { tabs: [{title: '首頁(yè)'}, {title: '外賣(mài)'}, {title: '商超生鮮'}, {title: '購(gòu)物'}, {title: '美食飲品'}, {title: '生活服務(wù)'}, {title: '休閑娛樂(lè)'}], activeTab: 0, tabSwiperHeight: 0 }, tabsSwiperHeight() { // tab 組件內(nèi)的swiper高度自適應(yīng)問(wèn)題 let index = this.data.activeTab; let queryDom = wx.createSelectorQuery() queryDom.select('.tab-content-' + index).boundingClientRect().exec(rect => { this.setData({ tabSwiperHeight: rect[0].height }) }) }, onTabCLick(e) { const index = e.detail.index this.setData({activeTab: index}) }, onChange(e) { const index = e.detail.index this.setData({activeTab: index}) this.tabsSwiperHeight(); } } |
工作日 8:30-12:00 14:30-18:00
周六及部分節(jié)假日提供值班服務(wù)