TDesign电商小程序模板解析01-自定义底部导航栏(二)

简介: TDesign电商小程序模板解析01-自定义底部导航栏(二)

3 创建底部导航条


我们底部导航条作为一级页面,可以使用微信自带的tabBar组件,配置方法是直接在app.json文件里增加对应的属性。导航条可以使用图标+文字的方案,图标有两种一种是选中状态,一种是未选中状态。

"tabBar": {
    "custom": true,
    "color": "#666666",
    "selectedColor": "#FF5F15",
    "backgroundColor": "#ffffff",
    "borderStyle": "black",
    "list": [
      {
        "pagePath": "pages/home/home",
        "text": "首页"
      },
      {
        "pagePath": "pages/goods/category/index",
        "text": "分类"
      },
      {
        "pagePath": "pages/cart/index",
        "text": "购物车"
      },
      {
        "pagePath": "pages/usercenter/index",
        "text": "我的"
      }
    ]
  }


把这个配置添加到app.json发现底部菜单栏并没有出现,原因是现在我们设置了cutom为true,表示我们要自己定义菜单栏的表现形式,因此需要在根目录创建一个custom-tab-bar文件夹


在文件夹下建立如下文件


在index.json里输入如下配置

{
  "component": true,
  "usingComponents": {
    "t-tab-bar": "tdesign-miniprogram/tab-bar/tab-bar",
    "t-tab-bar-item": "tdesign-miniprogram/tab-bar-item/tab-bar-item",
    "t-icon": "tdesign-miniprogram/icon/icon"
  }
}


component为true表示这是一个自定义组件,下边引入了三个框架自带组件


在data.js里输入如下代码

export default [
  {
    icon: 'home',
    text: '首页',
    url: 'pages/home/home',
  },
  {
    icon: 'sort',
    text: '分类',
    url: 'pages/goods/category/index',
  },
  {
    icon: 'cart',
    text: '购物车',
    url: 'pages/cart/index',
  },
  {
    icon: 'person',
    text: '个人中心',
    url: 'pages/usercenter/index',
  },
];


这里导出了一个数组,数组里的元素是菜单的具体配置,包括图标、文字名称和路径,但这里icon并没有指名路径,是使用框架自带的图标


剩下的配置我们就不解读了,官方已经编写好了,我们只需要复用他的代码就可以


index.js

import TabMenu from './data';
Component({
  data: {
    active: 0,
    list: TabMenu,
  },
  methods: {
    onChange(event) {
      this.setData({ active: event.detail.value });
      wx.switchTab({
        url: this.data.list[event.detail.value].url.startsWith('/')
          ? this.data.list[event.detail.value].url
          : `/${this.data.list[event.detail.value].url}`,
      });
    },
    init() {
      const page = getCurrentPages().pop();
      const route = page ? page.route.split('?')[0] : '';
      const active = this.data.list.findIndex(
        (item) =>
          (item.url.startsWith('/') ? item.url.substr(1) : item.url) ===
          `${route}`,
      );
      this.setData({ active });
    },
  },
});


index.wxml

<t-tab-bar
 value="{{active}}"
 bindchange="onChange"
 split="{{false}}"
>
  <t-tab-bar-item
  wx:for="{{list}}"
  wx:for-item="item"
  wx:for-index="index"
  wx:key="index"
  >
  <view class="custom-tab-bar-wrapper">
    <t-icon prefix="wr" name="{{item.icon}}" size="48rpx" />
    <view class="text">{{ item.text }}</view>
  </view>
  </t-tab-bar-item>
</t-tab-bar>


index.wxss

.custom-tab-bar-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.custom-tab-bar-wrapper .text {
  font-size: 20rpx;
}


实际我们自己做的时候就是把这些代码依次的复制到对应的文件里,复制过去发现图标显示不了,需要再引入一个样式文件,在根目录建一个style文件夹,创建一个iconfont的wxss文件

样式文件的内容

@font-face {
    font-family: 'wr';
    src: url('https://cdn3.codesign.qq.com/icons/gqxWyZ1yMJZmVXk/Yyg5Zp2LG8292lK/iconfont.woff?t=cfc62dd36011e60805f5c3ad1a20b642')
      format('woff2');
  }
  .wr {
    font-family: 'wr' !important;
    font-size: 32rpx;
    font-style: normal;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
  .wr-deliver:before {
    content: '\e033';
  }
  .wr-indent_close:before {
    content: '\e041';
  }
  .wr-edit:before {
    content: '\e002';
  }
  .wr-succeed:before {
    content: '\e00d';
  }
  .wr-goods_return:before {
    content: '\e03c';
  }
  .wr-wallet:before {
    content: '\e051';
  }
  .wr-package:before {
    content: '\e047';
  }
  .wr-comment:before {
    content: '\e037';
  }
  .wr-exchang:before {
    content: '\e03e';
  }
  .wr-credit_card:before {
    content: '\e035';
  }
  .wr-service:before {
    content: '\e04a';
  }
  .wr-shop_bag:before {
    content: '\e02a';
  }
  .wr-goods_refund:before {
    content: '\e03d';
  }
  .wr-check:before {
    content: '\e053';
  }
  .wr-wechat:before {
    content: '\e065';
  }
  .wr-cartAdd:before {
    content: '\e05d';
  }
  .wr-home:before {
    content: '\e020';
  }
  .wr-person:before {
    content: '\e02c';
  }
  .wr-cart:before {
    content: '\e023';
  }
  .wr-location:before {
    content: '\e016';
  }
  .wr-arrow_forward:before {
    content: '\e012';
  }
  .wr-close:before {
    content: '\e021';
  }
  .wr-search:before {
    content: '\e011';
  }
  .wr-clear_filled:before {
    content: '\e027';
  }
  .wr-arrow_drop_up:before {
    content: '\e071';
  }
  .wr-arrow_drop_down:before {
    content: '\e070';
  }
  .wr-filter:before {
    content: '\e038';
  }
  .wr-copy:before {
    content: '\e001';
  }
  .wr-arrow_back:before {
    content: '\e003';
  }
  .wr-add_circle:before {
    content: '\e004';
  }
  .wr-Download:before {
    content: '\e006';
  }
  .wr-map:before {
    content: '\e007';
  }
  .wr-store:before {
    content: '\e008';
  }
  .wr-movie:before {
    content: '\e00a';
  }
  .wr-done:before {
    content: '\e00b';
  }
  .wr-minus:before {
    content: '\e00c';
  }
  .wr-list:before {
    content: '\e00e';
  }
  .wr-expand_less:before {
    content: '\e00f';
  }
  .wr-person_add:before {
    content: '\e010';
  }
  .wr-Photo:before {
    content: '\e013';
  }
  .wr-preview:before {
    content: '\e014';
  }
  .wr-remind:before {
    content: '\e015';
  }
  .wr-info:before {
    content: '\e017';
  }
  .wr-expand_less_s:before {
    content: '\e018';
  }
  .wr-arrow_forward_s:before {
    content: '\e019';
  }
  .wr-expand_more_s:before {
    content: '\e01a';
  }
  .wr-share:before {
    content: '\e01d';
  }
  .wr-notify:before {
    content: '\e01e';
  }
  .wr-add:before {
    content: '\e01f';
  }
  .wr-Home:before {
    content: '\e020';
  }
  .wr-delete:before {
    content: '\e022';
  }
  .wr-error:before {
    content: '\e025';
  }
  .wr-sort:before {
    content: '\e028';
  }
  .wr-sort_filled:before {
    content: '\e029';
  }
  .wr-shop_bag_filled:before {
    content: '\e02b';
  }
  .wr-person_filled:before {
    content: '\e02d';
  }
  .wr-cart_filled:before {
    content: '\e02e';
  }
  .wr-home_filled:before {
    content: '\e02f';
  }
  .wr-add_outline:before {
    content: '\e030';
  }
  .wr-compass:before {
    content: '\e034';
  }
  .wr-goods_exchange:before {
    content: '\e03a';
  }
  .wr-group_buy:before {
    content: '\e03b';
  }
  .wr-group:before {
    content: '\e03f';
  }
  .wr-indent_goods:before {
    content: '\e040';
  }
  .wr-help:before {
    content: '\e042';
  }
  .wr-group_takeout:before {
    content: '\e043';
  }
  .wr-label:before {
    content: '\e044';
  }
  .wr-indent_wating:before {
    content: '\e045';
  }
  .wr-member:before {
    content: '\e046';
  }
  .wr-scanning:before {
    content: '\e04b';
  }
  .wr-tv:before {
    content: '\e04d';
  }
  .wr-to_top:before {
    content: '\e04f';
  }
  .wr-visibility_off:before {
    content: '\e050';
  }
  .wr-error-1:before {
    content: '\e052';
  }
  .wr-arrow_right:before {
    content: '\e054';
  }
  .wr-arrow_left:before {
    content: '\e056';
  }
  .wr-picture_filled:before {
    content: '\e057';
  }
  .wr-navigation:before {
    content: '\e058';
  }
  .wr-telephone:before {
    content: '\e059';
  }
  .wr-indent_time:before {
    content: '\e05c';
  }
  .wr-cart_add:before {
    content: '\e05d';
  }
  .wr-classify:before {
    content: '\e060';
  }
  .wr-place:before {
    content: '\e063';
  }
  .wr-wechat_pay:before {
    content: '\e064';
  }
  .wr-security:before {
    content: '\e066';
  }
  .wr-alarm:before {
    content: '\e067';
  }
  .wr-person-1:before {
    content: '\e068';
  }
  .wr-open_in_new:before {
    content: '\e069';
  }
  .wr-uncheck:before {
    content: '\e06b';
  }
  .wr-thumb_up:before {
    content: '\e06c';
  }
  .wr-thumb_up_filled:before {
    content: '\e06d';
  }
  .wr-star:before {
    content: '\e06e';
  }
  .wr-star_filled:before {
    content: '\e06f';
  }
  .wr-cards:before {
    content: '\e072';
  }
  .wr-picture_error_filled:before {
    content: '\e076';
  }
  .wr-discount:before {
    content: '\e077';
  }

然后需要在app.wxss里引入

@import 'style/iconfont.wxss';

一切配置好之后我们就把底部导航栏制作好了


总结


我们本篇带着大家搭建了一下TDesign电商模板的底部导航条功能,模板是使用自定义组件进行了搭建,还引入了自定义样式文件,稍稍有一点复杂,可以照着教程自己实验一下。

相关文章
|
Web App开发 移动开发 前端开发
React音频播放器样式自定义全解析:从入门到避坑指南
在React中使用HTML5原生&lt;audio&gt;标签时,开发者常面临视觉一致性缺失、样式定制局限和交互体验割裂等问题。通过隐藏原生控件并构建自定义UI层,可以实现完全可控的播放器视觉风格,避免状态不同步等典型问题。结合事件监听、进度条拖拽、浏览器兼容性处理及性能优化技巧,可构建高性能、可维护的音频组件,满足跨平台需求。建议优先使用成熟音频库(如react-player),仅在深度定制需求时采用原生方案。
586 12
|
人工智能 小程序 前端开发
【一步步开发AI运动小程序】十九、运动识别中如何解析RGBA帧图片?
本文介绍了如何将相机抽取的RGBA帧图像解析为`.jpg`或`.png`格式,适用于体测、赛事等场景。首先讲解了RGBA图像结构,其为一维数组,每四个元素表示一个像素的颜色与透明度值。接着通过`uni.createOffscreenCanvas()`创建离屏画布以减少绘制干扰,并提供代码实现,将RGBA数据逐像素绘制到画布上生成图片。最后说明了为何不直接使用拍照API及图像转换的调用频率建议,强调应先暂存帧数据,运动结束后再进行转换和上传,以优化性能。
|
数据采集 监控 搜索推荐
深度解析淘宝商品详情API接口:解锁电商数据新维度,驱动业务增长
淘宝商品详情API接口,是淘宝开放平台为第三方开发者提供的一套用于获取淘宝、天猫等电商平台商品详细信息的应用程序接口。该接口涵盖了商品的基本信息(如标题、价格、图片)、属性参数、库存状况、销量评价、物流信息等,是电商企业实现商品管理、市场分析、营销策略制定等功能的得力助手。
|
供应链 搜索推荐 API
深度解析1688 API对电商的影响与实战应用
在全球电子商务迅猛发展的背景下,1688作为知名的B2B电商平台,为中小企业提供商品批发、分销、供应链管理等一站式服务,并通过开放的API接口,为开发者和电商企业提供数据资源和功能支持。本文将深入解析1688 API的功能(如商品搜索、详情、订单管理等)、应用场景(如商品展示、搜索优化、交易管理和用户行为分析)、收益分析(如流量增长、销售提升、库存优化和成本降低)及实际案例,帮助电商从业者提升运营效率和商业收益。
593 20
|
设计模式 XML Java
【23种设计模式·全精解析 | 自定义Spring框架篇】Spring核心源码分析+自定义Spring的IOC功能,依赖注入功能
本文详细介绍了Spring框架的核心功能,并通过手写自定义Spring框架的方式,深入理解了Spring的IOC(控制反转)和DI(依赖注入)功能,并且学会实际运用设计模式到真实开发中。
【23种设计模式·全精解析 | 自定义Spring框架篇】Spring核心源码分析+自定义Spring的IOC功能,依赖注入功能
|
JSON 小程序 UED
微信小程序 app.json 配置文件解析与应用
本文介绍了微信小程序中 `app.json` 配置文件的详细
2251 12
|
JSON 缓存 API
解析电商商品详情API接口系列,json数据示例参考
电商商品详情API接口是电商平台的重要组成部分,提供了商品的详细信息,支持用户进行商品浏览和购买决策。通过合理的API设计和优化,可以提升系统性能和用户体验。希望本文的解析和示例能够为开发者提供参考,帮助构建高效、可靠的电商系统。
658 12
|
搜索推荐 测试技术 API
探秘电商API:从测试到应用的深度解析与实战指南
电商API是电子商务背后的隐形引擎,支撑着从商品搜索、购物车更新到支付处理等各个环节的顺畅运行。它通过定义良好的接口,实现不同系统间的数据交互与功能集成,确保订单、库存和物流等信息的实时同步。RESTful、GraphQL和WebSocket等类型的API各自适用于不同的应用场景,满足多样化的需求。在测试方面,使用Postman、SoapUI和jMeter等工具进行全面的功能、性能和安全测试,确保API的稳定性和可靠性。未来,随着人工智能、大数据和物联网技术的发展,电商API将进一步智能化和标准化,为用户提供更个性化的购物体验,并推动电商行业的持续创新与进步。
758 5
|
监控 数据可视化 数据挖掘
直播电商复盘全解析:如何通过工具提升团队效率
直播电商作为新兴商业模式,正改变传统零售格局。其成功不仅依赖主播表现和产品吸引力,更需团队高效协作与分工优化。复盘是提升执行力的关键环节,通过总结经验、发现问题、优化流程,结合在线工具如板栗看板,可提升复盘效率。明确团队角色、建立沟通机制、制定优化方案,确保数据驱动决策,从而在竞争中保持领先。
|
缓存 NoSQL Java
千万级电商线上无阻塞双buffer缓冲优化ID生成机制深度解析
【11月更文挑战第30天】在千万级电商系统中,ID生成机制是核心基础设施之一。一个高效、可靠的ID生成系统对于保障系统的稳定性和性能至关重要。本文将深入探讨一种在千万级电商线上广泛应用的ID生成机制——无阻塞双buffer缓冲优化方案。本文从概述、功能点、背景、业务点、底层原理等多个维度进行解析,并通过Java语言实现多个示例,指出各自实践的优缺点。希望给需要的同学提供一些参考。
295 8

推荐镜像

更多
  • DNS