小程序底部导航按钮实现

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

最终实现效果如下所示

新建一个小程序项目,我是创建了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"
}
相关推荐
txc16 小时前
我用 AI 给两个人写了个微信小程序(二):从「能用」到「用得对」
微信小程序
海上彼尚18 小时前
【微信小程序】xxx该网站的安全证书存在问题,可选择 “继续”在浏览器中访问。
安全·微信小程序·小程序
andrsted21 小时前
练题簿在线免费刷题:个人备考,从练新题到模拟自测怎么用?
学习·微信小程序·小程序·学习方法·刷题
Data_Journal21 小时前
如何使用 Python 解析 HTML
python·html
多客:duokelijie1 天前
婚恋交友小程序合规梳理:上线运营需要准备哪些资质与许可手续?
后端·mysql·微信小程序·前端框架·uni-app·php·持续部署
java1234_小锋1 天前
【技术专题】HTML5 网页技术 - HTML5 Canvas 基础以及动画入门
前端·html·html5
创了么OPC1 天前
小程序能收款了,对公户还没开?独立开发者的交付闭环踩坑②
前端·微信小程序
keyipatience2 天前
TypeScript学习(1)
前端·javascript·学习·typescript·html·css3
一木 之林2 天前
微信小程序开发全攻略·文章版|05 路由·交互·网络与音乐播放器实战
网络·微信小程序·小程序·交互
niucloud-admin2 天前
NIUCLOUD LITE AI开发文档—模块开发:微信小程序
微信小程序·小程序·notepad++