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>

相关推荐
bug总结13 小时前
uniapp 微信小程序分包规范
微信小程序·小程序·uni-app
天府云创14 小时前
uni-app X 蒸汽模式发布!性能比肩原生~
前端框架·uni-app·移动开发·原生应用·蒸汽模式·app研发·多端适配
堕落年代17 小时前
uni-app x 蒸汽模式:实时流式语音识别(ASR)三大疑难杂症全记录
人工智能·uni-app·语音识别
RisunJan1 天前
uni-app 高频面试题与解答
uni-app
梦曦i1 天前
@meng-xi/create-uni-app vs unibest:轻量脚手架与重型框架的定位之争
前端·uni-app
2501_915106322 天前
iOS数据采集技术详解:从性能监控到崩溃分析的全链路实践
android·ios·小程序·https·uni-app·iphone·webview
我爱写代码i3 天前
AI对话绘画数字人源码 - uniapp前端
前端·人工智能·uni-app
ModyQyW3 天前
vite-plugin-uni-pages 更新了什么
前端·uni-app
2501_915918413 天前
Flutter项目配置iOS混淆的详细步骤与工具推荐
android·flutter·ios·小程序·uni-app·cocoa·iphone
梦曦i3 天前
create-uni-app v1.2.0:交互体验优化
前端·uni-app