小程序底部导航按钮实现

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

最终实现效果如下所示

新建一个小程序项目,我是创建了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"
}
相关推荐
Metaphor6926 小时前
使用 Python 将 PDF 转换为 HTML
python·pdf·html
a1117769 小时前
“黑夜流星“个人引导页 网页html
java·前端·html
JieE21210 小时前
手把手带你用纯 CSS 实现一个 3D 旋转魔方,这些前端基础你能打几分?
前端·css·html
YHL12 小时前
🧊 CSS 3D 硬核解析:四个属性手写旋转立方体
前端·css·html
a11177612 小时前
无限森林漫游(简约几何版 html
前端·html
LaughingZhu13 小时前
Product Hunt 每日热榜 | 2026-06-16
前端·人工智能·经验分享·chatgpt·html
m0_547486661 天前
《HTML+CSS+JavaScript+Vue前端开发技术教程》全套PPT课件
javascript·css·html
fastjson_1 天前
Edge浏览器开启IE兼容模式
javascript·edge·html
艾伦野鸽ggg1 天前
web 组大一下第二次考核
前端·css·html
玩烂小程序1 天前
微信小程序手串DIY功能开发实录:飞入动画 + 环形排布 + 拖拽换序 + 旋转查看 + 保存设计
微信小程序