uni-app - - - - - 自定义tabbar

2024-08-28 11:36
文章标签 自定义 app uni tabbar

本文主要是介绍uni-app - - - - - 自定义tabbar,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

uni-app - - - - - 自定义tabbar

  • 1. 创建页面
  • 2. pages.json
  • 3. 自定义tabbar
  • 4. 隐藏原生tabbar
  • 5. 全局注册组件
  • 6. 页面使用
  • 7. 效果图展示

1. 创建页面

在这里插入图片描述

2. pages.json

配置tabbar

{"tabBar": {"list": [{"pagePath": "pages/ballroom/ballroom","text": "球类房"},{"pagePath": "pages/gym/gym","text": "健身房"},{"pagePath": "pages/yoga-room/yoga-room","text": "瑜伽室"},{"pagePath": "pages/league-class/league-class","text": "团课"},{"pagePath": "pages/my-reservation/my-reservation","text": "我的预定"}]}
}

3. 自定义tabbar

在这里插入图片描述

<!-- 自定义底部导航栏 -->
<template><view class="tabbar-container" :style="{backgroundImage:'url('+bg+')'}"><!-- :style="['width: calc(100% /' + tabbar.length + ')']" --><view class="tabbar-item" :class="[item.centerItem ? ' center-item' : '']" @click="changeItem(item)"v-for="(item, i) in tabbar" :key="i"><view class="item-top"><image :src="curItem === item.id ? item.selectedIconPath : item.iconPath" /></view><view class="item-bottom" :class="[curItem === item.id ? 'item-active' : '']">{{ item.text }}</view></view></view>
</template><script>export default {props: {/* 当前导航栏 */currPage: {type: Number,default: 0}},data() {return {curItem: 0, // 当前所选导航栏bg: 'https://*******/tabbar-bg.jpg',tabbar: [{id: 0,pagePath: "/pages/ballroom/ballroom",text: "球类房",iconPath: '/static/tabbar-icon/ball.png',selectedIconPath: '/static/tabbar-icon/ball-actived.png',centerItem: false},{id: 1,pagePath: "/pages/gym/gym",text: "健身房",iconPath: '/static/tabbar-icon/gym.png',selectedIconPath: '/static/tabbar-icon/gym-actived.png',centerItem: false},{id: 2,pagePath: "/pages/yoga-room/yoga-room",text: "瑜伽室",iconPath: '/static/tabbar-icon/yoga.png',selectedIconPath: '/static/tabbar-icon/yoga-actived.png',centerItem: false},{id: 3,pagePath: "/pages/league-class/league-class",text: "团课",iconPath: '/static/tabbar-icon/league.png',selectedIconPath: '/static/tabbar-icon/league-actived.png',centerItem: false},{id: 4,pagePath: "/pages/my-reservation/my-reservation",text: "我的预定",iconPath: '/static/tabbar-icon/my-reservation.png',selectedIconPath: '/static/tabbar-icon/my-reservation-actived.png',centerItem: false}] // 导航栏列表};},mounted() {this.curItem = this.currPage; // 当前所选导航栏// #ifdef H5uni.hideTabBar(); // 隐藏 tabBar 导航栏// #endifthis.curItem = this.currPage; // 当前所选导航栏},methods: {/* 导航栏切换 */changeItem(e) {console.log('切换tab', e.pagePath)// #ifdef MP-WEIXINuni.switchTab({url: e.pagePath,fail: function(error) {console.error("Failed to navigate:", error);}}); // 跳转到其他 tab 页面// #endif// #ifdef MP-ALIPAYuni.switchTab({url: e.pagePath,fail: function(error) {console.error("Failed to navigate:", error);}}); // 跳转到其他 tab 页面// #endif}}};
</script><style lang="scss" scoped>$textDefaultColor: #999; // 文字默认颜色$bottomBg: #fff; // 底部背景$textSelectedColor: #E51717; // 文字选中颜色$centerItemBg: #fff; // 中间凸起按钮背景.tabbar-container {position: fixed;bottom: 0;left: 0;display: flex;width: 100%;height: 188rpx;color: $textDefaultColor;box-shadow: 0 0 10rpx #999;background-size: 100% 100%;background-color: #ccc;}.tabbar-item {display: flex;flex-direction: column;justify-content: center;align-items: center;text-align: center;width: 150rpx;height: 120rpx;position: relative;.item-top {flex-shrink: 0;width: 150rpx;height: 120rpx;// background-color: aqua;// width: 65rpx;// height: 65rpx;// padding: 4rpx;image {width: 150rpx;height: 120rpx}}.item-bottom {width: 100%;font-size: 20rpx;position: absolute;bottom: 10rpx;}.item-active {color: $textSelectedColor;}}.center-item {position: relative;.item-top {position: absolute;top: -55rpx;left: 50%;transform: translateX(-50%);width: 105rpx;height: 105rpx;background-color: $centerItemBg;border-radius: 50%;}.item-bottom {position: absolute;bottom: 5rpx;}}
</style>

4. 隐藏原生tabbar

App.vue

		onLaunch: function() {console.log('App Launch')// #ifdef MP-ALIPAYuni.hideTabBar()// #endif// #ifdef MP-WEIXINuni.hideTabBar()// #endif},

5. 全局注册组件

main.js

import Vue from 'vue'
import './uni.promisify.adaptor'

6. 页面使用

<template><view class="common-containter">团课<custom-tabbar :curr-page="3" /></view>
</template><script>export default {data() {return {};}}
</script><style lang="scss"></style>

7. 效果图展示

在这里插入图片描述

这篇关于uni-app - - - - - 自定义tabbar的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1114649

相关文章

使用Sentinel自定义返回和实现区分来源方式

《使用Sentinel自定义返回和实现区分来源方式》:本文主要介绍使用Sentinel自定义返回和实现区分来源方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Sentinel自定义返回和实现区分来源1. 自定义错误返回2. 实现区分来源总结Sentinel自定

如何自定义Nginx JSON日志格式配置

《如何自定义NginxJSON日志格式配置》Nginx作为最流行的Web服务器之一,其灵活的日志配置能力允许我们根据需求定制日志格式,本文将详细介绍如何配置Nginx以JSON格式记录访问日志,这种... 目录前言为什么选择jsON格式日志?配置步骤详解1. 安装Nginx服务2. 自定义JSON日志格式各

Android自定义Scrollbar的两种实现方式

《Android自定义Scrollbar的两种实现方式》本文介绍两种实现自定义滚动条的方法,分别通过ItemDecoration方案和独立View方案实现滚动条定制化,文章通过代码示例讲解的非常详细,... 目录方案一:ItemDecoration实现(推荐用于RecyclerView)实现原理完整代码实现

基于Spring实现自定义错误信息返回详解

《基于Spring实现自定义错误信息返回详解》这篇文章主要为大家详细介绍了如何基于Spring实现自定义错误信息返回效果,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录背景目标实现产出背景Spring 提供了 @RestConChina编程trollerAdvice 用来实现 HTT

Android App安装列表获取方法(实践方案)

《AndroidApp安装列表获取方法(实践方案)》文章介绍了Android11及以上版本获取应用列表的方案调整,包括权限配置、白名单配置和action配置三种方式,并提供了相应的Java和Kotl... 目录前言实现方案         方案概述一、 androidManifest 三种配置方式

SpringSecurity 认证、注销、权限控制功能(注销、记住密码、自定义登入页)

《SpringSecurity认证、注销、权限控制功能(注销、记住密码、自定义登入页)》SpringSecurity是一个强大的Java框架,用于保护应用程序的安全性,它提供了一套全面的安全解决方案... 目录简介认识Spring Security“认证”(Authentication)“授权” (Auth

SpringBoot自定义注解如何解决公共字段填充问题

《SpringBoot自定义注解如何解决公共字段填充问题》本文介绍了在系统开发中,如何使用AOP切面编程实现公共字段自动填充的功能,从而简化代码,通过自定义注解和切面类,可以统一处理创建时间和修改时间... 目录1.1 问题分析1.2 实现思路1.3 代码开发1.3.1 步骤一1.3.2 步骤二1.3.3

dubbo3 filter(过滤器)如何自定义过滤器

《dubbo3filter(过滤器)如何自定义过滤器》dubbo3filter(过滤器)类似于javaweb中的filter和springmvc中的intercaptor,用于在请求发送前或到达前进... 目录dubbo3 filter(过滤器)简介dubbo 过滤器运行时机自定义 filter第一种 @A

CSS自定义浏览器滚动条样式完整代码

《CSS自定义浏览器滚动条样式完整代码》:本文主要介绍了如何使用CSS自定义浏览器滚动条的样式,包括隐藏滚动条的角落、设置滚动条的基本样式、轨道样式和滑块样式,并提供了完整的CSS代码示例,通过这些技巧,你可以为你的网站添加个性化的滚动条样式,从而提升用户体验,详细内容请阅读本文,希望能对你有所帮助...

macOS怎么轻松更换App图标? Mac电脑图标更换指南

《macOS怎么轻松更换App图标?Mac电脑图标更换指南》想要给你的Mac电脑按照自己的喜好来更换App图标?其实非常简单,只需要两步就能搞定,下面我来详细讲解一下... 虽然 MACOS 的个性化定制选项已经「缩水」,不如早期版本那么丰富,www.chinasem.cn但我们仍然可以按照自己的喜好来更换