uni-app uView自定义底部导航栏

因项目需要自定义底部导航栏,我把它写在了组件里,基于uView2框架写的(vue2);

一、代码

 在components下创建tabbar.vue文件,代码如下:

<template>
    <view>
    <u-tabbar :value="current?current:0" @change="changeTab" :fixed="true" :placeholder="false"
        :safeAreaInsetBottom="true" :border="false" activeColor="#40c6a2" inactiveColor="#B9BCBF">
        <u-tabbar-item v-for="(item,index) in list" :key="index" :text="item.text">
            <image class="u-page__item__slot-icon" slot="active-icon" :src="item.selectedIconPath"></image>
            <image class="u-page__item__slot-icon" slot="inactive-icon" :src="item.iconPath"></image>
        </u-tabbar-item>
    </u-tabbar>
    </view>
</template>

<script>
    export default {
        name: "TabBar",
        props: {
            current: Number
        },
        data() {
            return {
                list: [{
                    iconPath: "/static/images/salesRecords.png",
                    selectedIconPath: "/static/images/salesRecords_a.png",
                    pagePath: "pages/salesRecords/index",
                    text: "销售记录",
                    customIcon: false,
                }, {
                    iconPath: "/static/images/mine.png",
                    selectedIconPath: "/static/images/mine_a.png",
                    pagePath: "pages/mine/index",
                    text: "个人中心",
                    customIcon: false,
                }],
            }
        },
        methods: {
            // 跳转页面
            changeTab(e) {
                uni.switchTab({
                    url: '/' + this.list[e].pagePath,
                })
            }
        }
    }
</script>

 app.vue(有没有大佬知道为什么这个样式加载app.vue里才生效)

/* 导航样式 */
.u-tabbar__content {
    box-shadow: 0rpx 0rpx 10rpx 2rpx rgba(180, 203, 199, 0.4);
}  
.u-page__item__slot-icon {
    width: 40rpx;
    height: 40rpx;
}

二、配置

 pages.json配置

"tabBar": {
		"custom": true,
		"list": [
			{
				"pagePath": "pages/salesRecords/index"
			}, 
			{
				"pagePath": "pages/mine/index"
			}
		]
	},

三、使用

页面使用:mine.vue

注:current是底部导航栏的下标,你在tabbar页面的list中写的页面下标从0开始依次递增(如:我这个mine.vue的下标是1,在页面里引用组件时要加上:current="1"

有不懂的可以留言...

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 10
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值