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>

相关推荐
不法6 小时前
uniapp map地图导航/地图路线
前端·vue.js·uni-app
淡淡的幼稚1 天前
【YFIOs】从传感芯片到表格曲线
uni-app·.net
宠友信息1 天前
多端即时通讯源码技术实践,Redis路由、MySQL持久化与Socket接入
spring boot·websocket·mysql·uni-app
宠友信息1 天前
Spring Boot与异步审核构建仿小红书源码内容发布全流程
java·数据库·spring boot·redis·mysql·oracle·uni-app
蜡台1 天前
uniapp vue2 转 vue3
前端·javascript·uni-app·vue3·vue2
2501_916008892 天前
iOS 证书管理最佳实践 从创建到续期的完整指南
android·ios·小程序·https·uni-app·iphone·webview
敖行客 Allthinker2 天前
UniApp iOS APNs 推送证书一站式配置
uni-app·mac
梦曦i2 天前
uni-router新推useUniEventChannel,彻底解决页面通信难题
前端·uni-app
宠友信息2 天前
内容社区源码多端数据协议与 Spring Boot 状态流转实现思路
java·spring boot·websocket·uni-app
2501_916007472 天前
iPad 怎么抓包 从代理模式到暴力抓包的操作方法
android·ios·小程序·uni-app·代理模式·iphone·ipad