小程序(三)配置tabbar及自定义tabbar样式

您所在的位置:网站首页 小程序入口页面图片怎么设置的 小程序(三)配置tabbar及自定义tabbar样式

小程序(三)配置tabbar及自定义tabbar样式

2024-07-07 04:54:47| 来源: 网络整理| 查看: 265

关于tabbar部分,官方文档是有明确的说明的,当然,我这里是不存在把官方文档给你复制一遍的情况。我大概把我再看官方文档过程中遇到的坑,大概复述一下。

一:配置tabbar

这个主要是使用小程序自带的tabbar,在项目根目录下的app.json中配置,这个简单配置一下就可以了。

这里放一下我的app.json配置:

{ "pages": [ "pages/index/index", "pages/logs/logs", "pages/article/article", "pages/board/board", "pages/remark/remark" ], "tabBar": { "selectedColor": "#31869B", "list": [ { "current": 0, "pagePath": "pages/index/index", "text": "首页", "iconPath": "/images/index-select.png", "selectedIconPath": "/images/index-selected.png" }, { "current": 1, "pagePath": "pages/remark/remark", "text": "随言碎语", "iconPath": "/images/sui-select.png", "selectedIconPath": "/images/sui-selected.png" }, { "current": 2, "pagePath": "pages/board/board", "text": "留言板", "iconPath": "/images/board-select.png", "selectedIconPath": "/images/board-selected.png" } ] }, "usingComponents": { "weuitabbar": "/miniprogram_npm/weui-miniprogram/tabbar/tabbar" }, "window": { "backgroundTextStyle": "light", "navigationBarBackgroundColor": "#fff", "navigationBarTitleText": "WeChat", "navigationBarTextStyle": "black" }, "style": "v2", "sitemapLocation": "sitemap.json" }

更详细的tabbar配置属性说明,请移步官方文档《tabbar》

最后效果如下图所示:

在这里插入图片描述

二:自定义tabbar

有些时候,官方的样式并不能满足我们的要求,这个时候,我们就需要自定义tabbar的样式,当然,这个官方也是有说明的,只是,说明比较简单,官方给了一段示例代码。具体请移步官方文档《自定义tabbar》

然后,我这里大概分享下我是怎么写的:

App.json中,tabbar有一个custom属性,这个很重要,如果将这个属性设置为true,那么程序会默认使用自定义的tabbar。

那么我的app.json中的tabbar部分代码,就变成了下面的这个样子:

"tabBar": { "custom": true, },

在小程序根目录下创建目录custom-tab-bar,名字一定要是这个,别瞎起名。

在目录中创建组件index,注意,这里一定要注意,这里创建的是组件,而不是页面,虽然他们都是四个文件,但是他们是完全不一样的。

创建成功之后,文件目录如下图所示:

在这里插入图片描述

然后,我们开始编写四个文件中的代码:

(1):index.js

Component({ data: { selected: 0, color: "#7A7E83", selectedColor: "#31869B", fontWeight:'bold', "list": [ { "current": 0, "pagePath": "/pages/index/index", "text": "首页", "iconPath": "/images/index-select.png", "selectedIconPath": "/images/index-selected.png" }, { "current": 1, "pagePath": "/pages/remark/remark", "text": "随言碎语", "iconPath": "/images/sui-select.png", "selectedIconPath": "/images/sui-selected.png" }, { "current": 2, "pagePath": "/pages/board/board", "text": "留言板", "iconPath": "/images/board-select.png", "selectedIconPath": "/images/board-selected.png" } ] }, attached() { }, methods: { switchTab(e) { console.log(e); const idx = e.currentTarget.dataset.index const path = e.currentTarget.dataset.path // this.setData({ // selected: idx // }) wx.switchTab({ url: path, }); } } })

(2):index.json

这里边本来我打算用weui的tabbar组件来着,但是目前还没玩明白,这个回头再说。

{ "component": true, "usingComponents": { "weuitabbar": "/miniprogram_npm/weui-miniprogram/tabbar/tabbar" } }

(3):index.wxml



【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭