微信小程序+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 预览图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值