小程序底部导航按钮实现

商城小程序需要四个底部导航按钮,遂记录一下实现过程

最终实现效果如下所示

新建一个小程序项目,我是创建了JS模板,项目创建完成后需要新建五个文件夹,其中四个(page子文件夹)用于存放pages文件,一个sources文件夹(与pages同级)用于存放资源文件,如图标文件

图标需要8个,因为选中的图标和未选中的图标需要进行区分

图标文件源于阿里巴巴矢量图库

需要在app.json中添加以下配置信息,其中tabBar是新增的,其余均为系统默认生成

复制代码
{
  "pages": [
    "pages/Homepage/Homepage",
    "pages/index/index",
    "pages/logs/logs",
    "pages/Mine/mine",
    "pages/Recommend/recommend",
    "pages/ShoppingCart/shoppingCart"
  ],
  "tabBar": {
    "color": "#A9A9A9",
    "selectedColor": "#000000",
    "backgroundColor": "#FFFFFF",
    "borderStyle": "black",
    "position": "bottom",
    "custom": false,
    "list": [
      {
        "pagePath": "pages/Homepage/Homepage",
        "text": "首页",
        "iconPath": "source/img/main.png",
        "selectedIconPath": "source/img/main_selected.png"
      },
      {
        "pagePath": "pages/Recommend/recommend",
        "text": "推荐",
        "iconPath": "source/img/star.png",
        "selectedIconPath": "source/img/star_selected.png"
      },
      {
        "pagePath": "pages/ShoppingCart/shoppingCart",
        "text": "购物车",
        "iconPath": "source/img/shop.png",
        "selectedIconPath": "source/img/shop_selected.png"
      },
      {
        "pagePath": "pages/Mine/mine",
        "text": "个人中心",
        "iconPath": "source/img/my.png",
        "selectedIconPath": "source/img/my_selected.png"
      }
    ]
  },
  "window": {
    "navigationBarTextStyle": "black",
    "navigationBarTitleText": "Weixin",
    "navigationBarBackgroundColor": "#ffffff"
  },
  "style": "v2",
  "componentFramework": "glass-easel",
  "sitemapLocation": "sitemap.json",
  "lazyCodeLoading": "requiredComponents"
}
相关推荐
就叫飞六吧1 小时前
F12 控制台日志移植到页面案例
javascript·css·html
言乐614 小时前
Python快速生成工作报告
python·系统架构·html·交互·软件构建
西柚小萌新21 小时前
【论文写作】--LaTeX详细入门教程2
前端·html
winfredzhang2 天前
为长阅读而生:我做了一个「安静」的 PDF 阅读器
pdf·html
衍生星球2 天前
SpringBoot3 + Vue3 + 微信小程序如何学习,以及学哪些技术,组件
sql·微信小程序·uni-app·vue·springboot
u0143781082 天前
行内块元素之间的空白
前端·html
触底反弹2 天前
🎲 纯 CSS 搞定 3D 旋转立方体?还附赠一个「天坑」解决方案!
前端·css·html
LaughingZhu2 天前
Product Hunt 每日热榜 | 2026-07-06
前端·人工智能·经验分享·chatgpt·html
神奇的代码在哪里2 天前
AI编程时代,PPT已成为过去,单个HTML文件创造无限可能
javascript·html·powerpoint·ai编程·ppt
杨超越luckly2 天前
Agent 应用指南:基于 OurAirports 的中国机场设施数据可视化
python·html·github·可视化·机场设施