微信小程序+vant的自定义tabBar

1.目录结构

2.创建custom-tab-bar文件夹

1、在代码根目录下添加入口文件:

custom-tab-bar/index.js
custom-tab-bar/index.json
custom-tab-bar/index.wxml
custom-tab-bar/index.wxss

 2.引入vant中 tabBar组件

app.jsonindex.json中引入组件,详细介绍见vant 快速上手

"usingComponents": {
  "van-tabbar": "@vant/weapp/tabbar/index",
  "van-tabbar-item": "@vant/weapp/tabbar-item/index"
}

3.编辑custom-tab-bar文件夹下的文件

index.wxml

可以根据自己的喜好做修改 https://vant-contrib.gitee.io/vant-weapp/#/tabbar

根据vant中给予的属性进行修改添加会让你的页面更加动人

<van-tabbar active="{{ active }}" active-color="#FF0000"   bind:change="onChange"  >


   <van-tabbar-item wx:for="{{list}}" data-path="{{item.pagePath}}"  wx:key="index"  >
    <image
      slot="icon"
      src="{{item.iconPath}}"
      mode="aspectFit"
      style="width: 30px; height: 18px;"
    />
    <image
      slot="icon-active"
      src="{{item.selectedIconPath}}"
      mode="aspectFit"
      style="width: 30px; height: 18px;"
    />
    {{item.text}}
  </van-tabbar-item>  


</van-tabbar>

index.js

Page({
  data: {
    active: 0,
    list:[ {
      "pagePath": "pages/index/index",
      "text": "首页",
      "iconPath": "../img/icon/home.png",
      "selectedIconPath": "../img/icon/home-o.png"
    },{
      "pagePath": "pages/index/index",
      "text": "电影/影院",
      "iconPath": "../img/icon/电影.png",
      "selectedIconPath": "../img/icon/电影-o.png"
    },{
      "pagePath": "pages/index/index",
      "text": "演出",
      "iconPath": "../img/icon/演出.png",
      "selectedIconPath": "../img/icon/演出-o.png"
    
    },{
      "pagePath": "pages/index/index",
      "text": "体育/赛事",
      "iconPath": "../img/icon/赛事.png",
      "selectedIconPath": "../img/icon/赛事-o.png"
   
    },{
      "pagePath": "pages/index/index",
      "text": "我的",
      "iconPath": "../img/icon/我的.png",
      "selectedIconPath": "../img/icon/我的-o.png"
    
    }
  ],
   
  },
  onChange(event) {
    this.setData({ active: event.detail });
  },
});

        还有两个文件根据自己需求做修改

4.在app.json加入tabBar

 "tabBar": {
    "selected": 0,
    "color": "#515151",
    "selectedColor": "#d81e06",
    "list": [
      {
        "pagePath": "pages/home/home",
        "text": "首页",
        "iconPath": "./img/icon/home.png",
        "selectedIconPath": "./img/icon/home-o.png"
      },
      {
        "pagePath": "pages/index/index",
        "text": "电影/影院",
        "iconPath": "./img/icon/电影.png",
        "selectedIconPath": "./img/icon/电影-o.png"
      },
      {
        "pagePath": "pages/index/index",
        "text": "演出",
        "iconPath": "./img/icon/演出.png",
        "selectedIconPath": "./img/icon/演出-o.png"
      },
      {
        "pagePath": "pages/index/index",
        "text": "体育/赛事",
        "iconPath": "./img/icon/赛事.png",
        "selectedIconPath": "./img/icon/赛事-o.png"
      },
      {
        "pagePath": "pages/index/index",
        "text": "我的",
        "iconPath": "./img/icon/我的.png",
        "selectedIconPath": "./img/icon/我的-o.png"
      }
    ]
  }

5 预览图

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
微信小程序中使用 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 组件库并进行配置,然后在页面中按照需求引入侧边导航栏组件并设置相应的属性和事件,最后在监听滚动事件中处理导航栏的样式即可。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值