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>

相关推荐
FinelyYang8 小时前
UniApp + LiveKit:Android 端为什么要用原生做屏幕共享,以及我们怎么落地的
android·uni-app
宠友信息15 小时前
IM系统开发技术路线分析,即时通讯源码助力快速搭建聊天应用
java·spring boot·redis·websocket·mysql·uni-app·vue
qq_316837752 天前
uniapp + Vite + ffmpeg-wasm 0.12.x 集成示例
ffmpeg·uni-app·wasm
游戏开发爱好者82 天前
开心上架是什么,一站式 Apple 开发者工作台总览
android·小程序·https·uni-app·iphone·webview
年年CODE2 天前
uni-app 实现 AI 流式问答:H5 EventSource 与微信小程序 onChunkReceived 的兼容方案
uni-app
lhldsg2 天前
从匿名倾诉到树洞社交:基于Spring Boot与uniapp的多端匿名社交系统设计与实现
spring boot·后端·uni-app
风月说与山鬼2 天前
七、uni-app页面与组件生命周期
前端·uni-app
PedroQue992 天前
Vue-Router 2.4.0 新增可控重定向功能
前端·uni-app
风月说与山鬼2 天前
十、uni-app路由跳转
前端·uni-app
梦曦i2 天前
RouterLink H5端控制台错误修复
前端·uni-app