better-scroll 和v-show导致不能滚动的bug

我是一个页面多个子组件,每个子组件都有一个BScroll,通过v-show判断显示子组件

<medical-card v-show="pageIndex == 0"></medical-card>
<health-records v-show="pageIndex == 1" ref="healthRecords" ></health-records>
 <historical-order v-show="pageIndex == 2" ref="historicalOrder"></historical-order>

导致后面两个子组件不能滚动
原因是 v-show=false 时 display为none 子组件没有高度导致内部的scroll没有高度,所以不能滚动
解决:判断v-show=true时主动刷新scroll

function tabsClickAction(index) {
      state.pageIndex = index;
      if (index == 1) {
        healthRecords.value.refreshPage();
      }
      if (index == 2) {
        historicalOrder.value.refreshPage();
      }
      console.log(state.pageIndex);
    }

子组件内部方法

function refreshPage() {
    scroll.value.refresh();
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容