uniapp自定义tabbar

第一步:配置好需要作为tabbar页面的路径,并将custom属性设置为true,

第二部:tabbar组件的封装

<template>

<view class="tabbar">

<view class="item" v-for="(item,index) in list" :key="index" @click="goNav(item.pagePath,index)">

<view class="flex h-column h-center">

<image :src="current==index?item.selectedIconPath:item.iconPath"></image>

<view class="name" :class="current==index?'name-select':''">

{{item.text}}

</view>

</view>

</view>

</view>

</template>

<script>

export default{

props: ['current'],

data(){

return{

list: [{

iconPath: "../../../static/meijia/icon_navhome.png",

selectedIconPath: "../../../static/meijia/icon_navh_home.png",

text: '首页',

pagePath: '/pages/index/index',

},

{

iconPath: "../../../static/meijia/icon_navmy.png",

selectedIconPath: "../../../static/meijia/icon_navh_my.png",

text: '我的',

pagePath: '/pages/my/index',

},

]

}

},

methods:{

goNav(url,index) {

uni.switchTab({

url: url

})

}

}

}

</script>

<style lang="scss" scoped>

.tabbar {

position: fixed;

left: 0;

bottom: 0;

width: 100%;

background-color: rgb(255, 255, 255);

// border-top: 2rpx solid rgb(213, 215, 214);

padding: 20rpx 50rpx;

display: flex;

justify-content: space-between;

.item {

display: flex;

align-items: center;

padding-bottom: 20rpx;

image {

width: 54rpx;

height: 54rpx;

}

.name {

color: rgb(151, 152, 154);

font-size: 24rpx;

}

.name-select {

color: #333;

font-weight: bold;

}

}

}

</style>

第三步:在组件中使用,current的值即当前页面在tabbar页面数组中的索引

<tabbar :current="0" ></tabbar>

相关推荐
笨笨狗吞噬者3 小时前
【uniapp】体验优化:开源工具集 uni-toolkit 发布
性能优化·微信小程序·uni-app
NoneSL5 小时前
Uniapp UTS插件开发实战:引入第三方SDK
前端·uni-app
_AaronWong13 小时前
微信小程序同声传译插件接入实战:语音识别功能完整实现指南
前端·微信小程序·uni-app
赵庆明老师21 小时前
Uniapp微信小程序开发:http请求封装。
http·微信小程序·uni-app
雪芽蓝域zzs21 小时前
uniapp AES 加密解密
开发语言·uni-app·c#
我是高手高手高高手21 小时前
uni-app x 左右滑动效果
uni-app
居安思危_Ho1 天前
RK平台Uniapp自启动缓存问题解决
android·缓存·uni-app·rk平台·uniapp资源文件
你真的可爱呀1 天前
uniapp学习【项目创建+项目结构解析】
学习·uni-app
小小弯_Shelby1 天前
uniApp App内嵌H5打开内部链接,返回手势(左滑右滑页面)会直接关闭H5项目
前端·uni-app
卷Java1 天前
百度AI车牌识别配置指南
java·开发语言·百度·uni-app·dubbo·微信公众平台