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

相关推荐
PieroPc8 小时前
Windows 驱动备份与恢复工具 CMD .bat
windows
波罗丁牌9 小时前
逆变与协变详解
windows·microsoft
映翰通朱工9 小时前
Windows 上位机 + EC3320:USB 转 CAN 通信实测(从接线到 SSH 收包)
windows·stm32·ssh
我是Superman丶10 小时前
【2026亲测】Wireshark安装教程 Windows系统|下载安装、Npcap配置及首次抓包
windows·测试工具·wireshark
贾天佑忆月 迷失的昵11 小时前
Direct3D Draw函数 异步调用原理解析
服务器·windows·性能优化
sg_knight12 小时前
Codex CLI 安装全攻略:macOS / Linux / Windows(WSL2)三端实战
linux·windows·macos·openai·ai编程·coding·codex
趣味科技1 天前
记录修复EAGET忆捷移动硬盘损坏
windows·数据分析·硬件工程
我命由我123451 天前
Java 开发 - List subList 方法
java·windows·操作系统·list·intellij-idea·idea·intellij idea
吃辣我第一1 天前
监听SHP目录自动注册SuperMap iServer地图服务(Windows版)
windows·iserver·shapefile
程序员老陆1 天前
FFmpeg6 在 Windows 打开麦克风并录成 PCM:不走 Qt Multimedia,也不碰 WASAPI
windows·ffmpeg·音视频·pcm