uniapp 设置底部导航栏

uniapp 设置原生 tabBar 底部导航栏。

设置底部导航栏

一、创建页面,一定要在 pages.json 文件中注册。

二、在 pages.json 文件中,设置 tabBar 配置项。

javascript 复制代码
pages.json 页面
{
  "pages": [...],
  "globalStyle": {...},
  "uniIdRouter": {...},
  // 其它配置...

  // 底部导航栏配置
  "tabBar": {
    "color": "#555555", // 文字颜色
    "selectedColor": "#FF5050", // 选中文字颜色
    "borderStyle": "white", // 上边框颜色 white 白色
    "backgroundColor": "#FFFFFF", // 背景颜色
    "list": [
      {
        "pagePath": "pages/a/a", // 页面路径
        "text": "首页", // 按钮文字
        "iconPath": "/static/home.png", // 默认图片
        "selectedIconPath": "/static/home-active.png" // 选中图片
      },
      {
        "pagePath": "pages/b/b", // 页面路径
        "text": "攻略", // 按钮文字
        "iconPath": "/static/strategy.png", // 默认图片
        "selectedIconPath": "/static/strategy-active.png" // 选中图片
      },
      {
        "pagePath": "pages/c/c", // 页面路径
        "text": "发布", // 按钮文字
        "iconPath": "/static/issue.png", // 默认图片
        "selectedIconPath": "/static/issue.png" // 选中图片
      },
      {
        "pagePath": "pages/d/d", // 页面路径
        "text": "排行榜", // 按钮文字
        "iconPath": "/static/ranking.png", // 默认图片
        "selectedIconPath": "/static/ranking-active.png" // 选中图片
      },
      {
        "pagePath": "pages/e/e", // 页面路径
        "text": "我的", // 按钮文字
        "iconPath": "/static/my.png", // 默认图片
        "selectedIconPath": "/static/my-active.png" // 选中图片
      }
    ]
  }

}

效果:

注:在 list 中最少配置 2 个页面,最多 5 个页面,另外不能使用网络图片。

设置徽标

一、在任意页面中,调用 uni.setTabBadge 方法,设置指定页面的徽标。

html 复制代码
<template>
  <view> 首页 </view>
</template>

<script>
  export default {
    // 其它配置项...
    mounted() {
      // 设置排行榜页面的徽标
      uni.setTabBarBadge({
        index: 3, // 页面下标
        text: '12', // text 的值必须是字符串
      })
    }
  }
</script>

效果:

原创作者:吴小糖

创作时间:2024.1.11

相关推荐
Vex2une17 小时前
电脑风扇吵、温度高怎么办?清灰、硅脂更换与风扇曲线调节指南
windows·清灰·电脑散热·风扇噪音大·硅脂更换·风扇曲线·cpu温度高
feasibility.21 小时前
电脑一天重启3次、WiFi还消失:蓝屏0x9F背后,是MT7921网卡撞上Windows电源管理
服务器·网络·windows·wifi·电脑·网卡·驱动
StarsGreen1 天前
Android系统相关命令介绍
android·windows
争不过朝夕,又念着往昔2 天前
C++20-概念与约束
windows·c++20
郝学胜-神的一滴3 天前
Effective Python 条款43:自定义容器类
开发语言·windows·python·pandas·scikit-learn·pyqt
解道Jdon3 天前
Rust重写OpenCode Rune:性能提升最高100倍
ide·windows·git·svn·eclipse·github·visual studio
Frag0ut3 天前
开源下载管理器MDM下载获取与实操指南:IDM的上位替代
windows·macos·mdm·下载管理器·断点续传·开源下载工具·idm替代
the3clipse4 天前
Windows 11 26H2 任务栏与开始菜单深度自定义指南:位置、图标、布局全掌握
windows·使用技巧·开始菜单·win11 26h2·任务栏设置·任务栏自定义
SeanQhl4 天前
中文 Windows 上跑 Python 定时任务——编码、路径、控制台三个坑
windows·python·编码·效率工具·定时任务
Vex2une4 天前
系统出问题不想重装?系统还原点创建与重置此电脑完整指南
windows·系统还原点·重置此电脑·系统还原怎么用·创建还原点·保留文件重置·系统保护开启