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>

相关推荐
疯狂的沙粒24 分钟前
uniapp 开发企业微信小程序,如何区别生产环境和测试环境?来处理不同的服务请求
微信小程序·uni-app·notepad++
知兀26 分钟前
【黑马程序员uniapp】项目配置、请求函数封装
uni-app
fakaifa5 小时前
【最新版】西陆洗车系统源码全开源+uniapp前端+搭建教程
java·小程序·uni-app·php·源码下载·西陆洗车·洗车小程序
anyup8 小时前
记一次解决 uni-app 真机运行时导致的白屏问题:Trae vs 通义灵码 vs Cursor
前端·uni-app·trae
getapi9 小时前
为什么 uni-app 开发的 App 没有明显出现屏幕适配问题Flutter 开发的 App 出现了屏幕适配问题
flutter·uni-app
老李不敲代码12 小时前
榕壹云健身预约系统:多门店管理的数字化解决方案(ThinkPHP+MySQL+UniApp实现)
mysql·微信小程序·uni-app·php·软件需求
iOS阿玮14 小时前
不想被苹果卡审最好错开这两个提审时间
uni-app·app·apple
每天都想着怎么摸鱼的前端菜鸟1 天前
uniapp开发app 实现简易的路由拦截器
vue.js·uni-app
随笔记1 天前
uniapp中获取设备wifi列表,已连接wifi信息
前端·javascript·uni-app
lqj_本人1 天前
鸿蒙OS&UniApp微服务架构实践:从设计到鸿蒙部署#三方框架 #Uniapp
架构·uni-app·harmonyos