Vant UI的Sidebar侧边导航组件单独设置滚动条

在Vue项目中使用Vant UI框架时,遇到Sidebar侧边导航组件的滚动条在整个屏幕的右侧:

 需要实现的效果是:左侧导航栏有单独的滚动条,右侧主体内容也有单独的滚动条,互不干涉。

 (效果是左侧和右侧都是有一个滚动条的)

html部分:

    <div class="cate-list">
      <div class="left-nav">
        <van-sidebar v-model="activeKey" @change="changeNav">
          <van-sidebar-item
            :title="item.cat_name"
            v-for="(item, index) in cateList"
            :key="index"
          />
        </van-sidebar>
      </div>
      <div class="cate-body">
        <div
          class="cate-body-item"
          v-for="(item, index) in catev2List"
          :key="index"
        >
          <div class="title">/ {{ item.cat_name }} /</div>
          <van-grid :border="false" :column-num="3">
            <van-grid-item
              v-for="(subitem, index2) in catev2List[index].children"
              :key="index2"
            >
              <img :src="subitem.cat_icon" />
              <span class="name">{{ subitem.cat_name }}</span>
            </van-grid-item>
          </van-grid>
        </div>
      </div>
    </div>

重点是css部分:左侧和右侧的盒子需要定宽定高,然后overflow设置为scroll。

高度可以用一屏幕的高减去底部导航栏的高度。

  .cate-list {
    display: flex;
    justify-content: space-between;
    .left-nav {
      width: 22%;
      height: calc(100vh -100px);
      overflow: scroll;
    }
    .cate-body {
      width: 78%;
      height: calc(100vh -100px);
      overflow: scroll;
      .title {
        margin-top: 40px;
        text-align: center;
        font-size: 26px;
        font-weight: bold;
      }
      img {
        width: 140px;
        height: 140px;
      }
      .name {
        font-size: 24px;
      }
    }
  }

  • 4
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
微信小程序中使用 Vant 组件库的侧边导航栏滚动,需要首先在项目中引入 Vant 组件库,并且按照 Vant 的文档进行组件的配置和使用。 首先,在项目根目录下的 `app.json` 文件中配置 Vant 组件的全局样式,示例如下: ```json { "style": "vant-weapp/dist/common/index" } ``` 然后在需要使用侧边导航栏滚动的页面中引入 Vant侧边导航组件,并按照需求设置好相关属性和事件,示例如下: ```html <van-sidebar show="{{ true }}" width="200rpx" :style="height: 100vh;"> <van-sidebar-item v-for="(item, index) in menuList" :key="index" :title="item.title" :dot="item.dot" :badge="item.badge" /> </van-sidebar> ``` 其中,`show` 属性用于控制侧边导航栏的显示与隐藏,`width` 属性用于设置导航栏的宽度,`:style` 属性用于设置导航栏的高度为可视区域的高度。 此外,需要根据实际需求在 `data` 数据中定义 `menuList` 数组,并为每个侧边导航栏项设置相应的标题、角标和小红点。 最后,在页面的生命周期函数中,通过监听滚动事件来实现侧边导航栏的滚动效果,示例如下: ```javascript Page({ onScroll: function(event) { // 根据滚动位置处理侧边导航栏的样式 } }) ``` 在监听滚动事件中,可以根据滚动位置来处理侧边导航栏的样式,例如高亮当前正在滚动的导航项。 总结起来,要在微信小程序中使用 Vant 组件库的侧边导航栏滚动,需要首先引入 Vant 组件库并进行配置,然后在页面中按照需求引入侧边导航组件设置相应的属性和事件,最后在监听滚动事件中处理导航栏的样式即可。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值