taro底部导航,Tabbar

embedded/2024/10/19 20:41:15/

没有特别的幸运,那么就特别的努力!!!

配置信息

官方给出:
在 app.config 中按正常填写 tabBar 项的相关配置(为了向下兼容),并把 tabBar 项的 custom 字段设置为 true。但我试过 custom设置为 false 才生效

1.app.config.js 文件配置

// app.config.js
export default defineAppConfig({pages: ["pages/index/index", "pages/complaint/index", "pages/mine/index"],window: {backgroundTextStyle: "light",navigationBarBackgroundColor: "#fff",navigationBarTitleText: "WeChat",navigationBarTextStyle: "black",},tabBar: {custom: false,color: "#000000",selectedColor: "#DC143C",backgroundColor: "#ffffff",list: [{pagePath: "pages/index/index",selectedIconPath: "images/tabbar_home_on.png",iconPath: "images/tabbar_home.png",text: "首页",},{pagePath: "pages/mine/index",selectedIconPath: "images/tabbar_my_on.png",iconPath: "images/tabbar_my.png",text: "个人中心",},],},
});

2.添加 custom-tab-bar

在 src 目录下添加 custom-tab-bar 目录,在里面书写组件,支持 React、Vue 和原生写法。

├── config
├── src
|   └── custom-tab-bar
|       ├── index.config.ts
|       └── index.tsx
└── package.json
// src/custom-tab-bar/index.tsx
import { Component } from 'react'
import Taro from '@tarojs/taro'
import { CoverView, CoverImage } from '@tarojs/components'import './index.scss'export default class Index extends Component {state = {selected: 0,color: '#000000',selectedColor: '#DC143C',list: [{pagePath: '/pages/index/index',selectedIconPath: '../images/tabbar_home_on.png',iconPath: '../images/tabbar_home.png',text: '首页'},{pagePath: '/pages/mine/index',selectedIconPath: '../images/tabbar_my_on.png',iconPath: '../images/tabbar_my.png',text: '个人中心'}]}switchTab(index, url) {this.setSelected(index)Taro.switchTab({ url })}setSelected (idx: number) {this.setState({selected: idx})}render() {const { list, selected, color, selectedColor } = this.statereturn (<CoverView className='tab-bar'><CoverView className='tab-bar-border'></CoverView>{list.map((item, index) => {return (<CoverView key={index} className='tab-bar-item' onClick={this.switchTab.bind(this, index, item.pagePath)}><CoverImage src={selected === index ? item.selectedIconPath : item.iconPath} /><CoverView style={{ color: selected === index ? selectedColor : color }}>{item.text}</CoverView></CoverView>)})}</CoverView>)}
}

3.底部组件都需要引入

// src/page/mine/index.tsx
import { View, Text } from '@tarojs/components'
import Taro,{ useLoad } from '@tarojs/taro'
import './index.scss'import type CustomTabBar from '../../custom-tab-bar'export default function Mine () {const pageCtx = Taro.getCurrentInstance().pageuseLoad(() => {const tabbar = Taro.getTabBar<CustomTabBar>(pageCtx)tabbar?.setSelected(1)})return (<View className='mine'><Text>mine-1</Text></View>)
}

希望能帮助到大家,同时祝愿大家在开发旅途中愉快!!!

拿着 不谢 请叫我“锤” !!!


http://www.ppmy.cn/embedded/128823.html

相关文章

2024-10-19 商业分析-如何做行业分析-记录

摘要: 2024-10-19 商业分析-如何做行业分析-记录 如何做行业分析 呃&#xff0c;首先谢谢各位抽时间来呃听我讲一下如何被做行业的分析。对&#xff0c;如果按更土的话讲&#xff0c;就如何防止被对方给忽悠了。因为我觉得我们做投资和做媒体有个共性&#xff0c;觉得因为我们…

Djang学习- URL反转

代码中url书写规范&#xff1a; 、 url反向解析 urls: path(test/url, views.test_url),path(test_result/<int:age>, views.test_result, name"rl") views: def test_url(request):return render(request, test_url.html)def test_result(request,age):re…

双向链接表的反向迭代器(更新)( VC 和 QT都已编译过关)

例子&#xff1a; int main() { _DList<int> lst { 9,8,7, 6,1,2,3,4,5,0 };sort(lst.begin(), lst.end());_pn(lst);sort(lst.rbegin(), lst.rend());_pn(lst);return 0; }输出&#xff1a; 反向迭代器&#xff1a;_DListNodeReverseIterator /// <summary>…

中小型医院网站:Spring Boot框架实践

6 系统测试 6.1 测试定义 系统测试主要是判断系统是否可以正常运行&#xff0c;功能模块是否可以实现操作。程序代码中是否有错误出现。测试程序是开发过程中的一个主要问题。就算系统完成的再好&#xff0c;再进行程序测试时也会也会发现一个重来没有被发现的错误信息。 测试不…

UDP/TCP协议

网络层只负责将数据包送达至目标主机&#xff0c;并不负责将数据包上交给上层的哪一个应用程序&#xff0c;这是传输层需要干的事&#xff0c;传输层通过端口来区分不同的应用程序。传输层协议主要分为UDP&#xff08;用户数据报协议&#xff09;和TCP&#xff08;传输控制协议…

QT开发:深入掌握 QtGui 和 QtWidgets 布局管理:QVBoxLayout、QHBoxLayout 和 QGridLayout 的高级应用

目录 引言 1. QVBoxLayout&#xff1a;垂直布局管理器 基本功能 创建 QVBoxLayout 添加控件 添加控件和设置对齐方式 设置对齐方式 示例代码与详解 2. QHBoxLayout&#xff1a;水平布局管理器 基本功能 创建 QHBoxLayout 添加控件 添加控件和设置对齐方式 设置对齐…

2.计算机网络_IP地址

IPv4的IP地址 1、分类IP IP地址的表示方式&#xff1a; IP地址在整个互联网中是唯一的&#xff0c;指明了连接到某个网络上的一个主机。IP地址用32位二进制数表示&#xff0c;每一个字节代表一段&#xff0c;如下图IP地址即为128.11.3.31。 什么是多归属主机&#xff1a; 当…

高等数学(第三章:一元积分学 ② )

一、积分的概念总结 【思考】: 什么情况下原函数存在? 原函数存在定理。 什么情况下可积? 可积的充分条件。 原函数存在与可积有什么关系? 原函数存在不一定可积,可积不一定原函数存在(当且仅当 f(x) 连续时,原函数存在与可积可以互推)。 ∫0x f(t) dt 一定是 f(x) 的…