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

本文涉及的产品
公共DNS(含HTTPDNS解析),每月1000万次HTTP解析
全局流量管理 GTM,标准版 1个月
云解析 DNS,旗舰版 1个月
简介: 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电商模板的底部导航条功能,模板是使用自定义组件进行了搭建,还引入了自定义样式文件,稍稍有一点复杂,可以照着教程自己实验一下。

相关文章
|
2月前
|
小程序 视频直播 UED
电商直播小程序系统开发:打造“直播+电商+社交”闭环
电商直播小程序成为商家与消费者互动的关键,通过微信提供的实时视频工具,实现流畅购物体验。系统功能包括直播预览、主播管理、红包互动、用户管理及闭环购物。它强化品牌效应,利用私域流量,简化流程并转化会员。开发涉及需求分析、设计规划、功能开发、测试优化及上线维护。企业需关注用户体验,以保持竞争力。寻求开发合作可联系相关人员。
|
1月前
|
机器学习/深度学习 供应链 大数据
【2023Mathorcup大数据】B题 电商零售商家需求预测及库存优化问题 python代码解析
本文提供了2023年MathorCup大数据竞赛B题的电商零售商家需求预测及库存优化问题的Python代码解析,涉及数据预处理、特征工程、时间序列预测、聚类分析以及模型预测性能评价等步骤。
82 0
|
5天前
|
C# Android开发 开发者
Uno Platform 高级定制秘籍:深度解析与实践样式和模板应用,助你打造统一且高效的跨平台UI设计
【9月更文挑战第7天】Uno Platform 是一个强大的框架,支持使用 C# 和 XAML 创建跨平台 UI 应用,覆盖 Windows、iOS、Android、macOS 和 WebAssembly。本文介绍 Uno Platform 中样式和模板的应用,助力开发者提升界面一致性与开发效率。样式定义控件外观,如颜色和字体;模板则详细定制控件布局。通过 XAML 定义样式和模板,并可在资源字典中全局应用或嵌套扩展。合理利用样式和模板能简化代码、保持设计一致性和提高维护性,帮助开发者构建美观高效的跨平台应用。
14 1
|
16天前
|
小程序 前端开发 JavaScript
【电商新机遇】支付宝小程序如何助你打造爆款电商解决方案?揭秘背后的技术奥秘!
【8月更文挑战第27天】本文详细介绍如何利用支付宝小程序构建电商应用,覆盖从项目初始化、页面设计、功能开发到数据分析的全流程。首先,需注册开发者账号并安装相关工具;随后创建项目,并按示例配置基本页面结构;接着设计商品列表等界面布局;再实现商品展示等功能;最后运用支付宝提供的工具进行数据分析,以优化用户体验及营销策略。跟随本教程,您将能打造出一款完整的电商小程序。
43 1
|
14天前
|
存储 数据采集 API
提升店铺好评秘籍:淘宝商品评论接口与电商 API 接口的深度解析
该接口名为item_review,用于获取淘宝商品评论信息,支持HTTP GET或POST请求,体验API为c0b.cc/R4rbK2。主要请求参数包括商品ID(num_iid)、排序方式(sort)、页码(page)。响应参数涵盖评论内容(rate_content)、评论日期(rate_date)、评论图片(pics)、买家昵称(display_user_nick)、商品属性(auction_sku)
|
2月前
|
开发框架 小程序 前端开发
私域电商小程序系统开发:提供可行的电商解决方案
私域电商小程序助广州企业融合线上线下业务,利用智能手机普及与网络技术,提供个性化购物体验。开发涉及需求分析、UI设计、前后端开发及测试上线。技术要点包括微信小程序框架、前端后端技术及安全优化。市场竞争需关注用户需求、特色服务、技术创新与合作推广。通过差异化策略抓住市场机遇。
|
2月前
|
小程序
商家店铺电商小程序模板源码
商家店铺电商小程序模板源码
30 5
|
2月前
|
中间件 数据库 开发者
解析Python Web框架的四大支柱:模板、ORM、中间件与路由
【7月更文挑战第20天】Python Web框架如Django、Flask、FastAPI的核心包括模板(如Django的DTL和Flask的Jinja2)、ORM(Django的内置ORM与Flask的SQLAlchemy)、中间件(Django的全局中间件与Flask的装饰器实现)和路由(Django的urls.py配置与Flask的@app.route()装饰器)。这些组件提升了代码组织和数据库操作的便捷性,确保了Web应用的稳定性和可扩展性。
43 0
|
3月前
|
SQL 自然语言处理 前端开发
【JavaScript】ECMAS6(ES6)新特性概览(一):变量声明let与const、箭头函数、模板字面量全面解析
【JavaScript】ECMAS6(ES6)新特性概览(一):变量声明let与const、箭头函数、模板字面量全面解析
34 2
|
2月前
|
小程序 安全 UED
百果园社区电商小程序开发:打造私域精准营销发展趋势
百果园借助社区电商小程序转型,拓展线上渠道,增强品牌形象,降低运营成本,适应市场变化。小程序提供实时购物、社群互动、商家入驻及优惠活动,强调用户体验、功能丰富性和安全性,成为品牌与消费者连接的新桥梁。

热门文章

最新文章

推荐镜像

更多