小程序怎么自定义tabBar组件封装
发表于:2025-02-01 作者:千家信息网编辑
千家信息网最后更新 2025年02月01日,这篇文章主要介绍"小程序怎么自定义tabBar组件封装",在日常操作中,相信很多人在小程序怎么自定义tabBar组件封装问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"小
千家信息网最后更新 2025年02月01日小程序怎么自定义tabBar组件封装
这篇文章主要介绍"小程序怎么自定义tabBar组件封装",在日常操作中,相信很多人在小程序怎么自定义tabBar组件封装问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"小程序怎么自定义tabBar组件封装"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
具体内容如下
1、新建组件:在component下新建一个tabBar
2、组件的index.wxml结构如下:
{{item.text}}
3、组件的index.wxss结构如下:
.tab-bar { position: fixed; bottom: 0; left: 0; right: 0; height: 60px; background: white; display: flex; padding-bottom: env(safe-area-inset-bottom);}.tab-bar-border { background-color: rgba(0, 0, 0, 0.33); position: absolute; left: 0; top: 0; width: 100%; height: 1px; transform: scaleY(0.5);}.tab-bar-item { flex: 1; text-align: center; display: flex; justify-content: center; align-items: center; flex-direction: column;}.tab-bar-item cover-image { width: 28px; height: 28px; margin-bottom: 2px;}.tab-bar-item cover-view { font-size: 10px;}
4、组件的index.js结构如下:
// pages/components/tabBar/index.jsComponent({ /** 1. 组件的属性列表 */ options: { multipleSlots: true //在组件定义时的选项中启用多slot支持 }, properties: { list: { type: Array, value: [] }, selectedColor:{ type: String, value:'' }, color:{ type: String, value:'' }, }, /** 2. 组件的初始数据 */ data: { tabbarIndex: 0//默认显示第一个tab元素 }, lifetimes: { attached() {} }, /** 3. 组件的方法列表 */ methods: { //组件的点击事件 tabChange(e) { //获取到底部栏元素的下标 let index = e.currentTarget.dataset.index; this.setData({ tabbarIndex:index, }) //triggerEvent获取组件的事件 //onMyEvent 页面传过来的点击事件名称 this.triggerEvent('onMyEvent',{ tabbarIndex:index, }) }, }})
5、组件的index.json结构如下:
{ "component": true, "usingComponents": {}}
6、组件在页面中的使用
7、页面的json代码如下:
{ "navigationBarTitleText": "测试", "usingComponents": { "mp-tabbar": "../components/tabBar/index" }}
8、页面的wxml代码如下:
//当选中tab1时页面显示的内容111111 //当选中tab2时页面显示的内容222222 //当选中tab3时页面显示的内容333333
9、页面的js代码如下:
Page({ data: { tabbarIndex:0,//默认第一个tab元素 color: "#555555", selectedColor: "#2ea7e0", //底部栏 list: [{ "text": "市场", "iconPath": "/images/bazaar.png", "selectedIconPath": "/images/bazaar_selected.png", }, { "text": "充值", "iconPath": "/images/recharge.png", "selectedIconPath": "/images/recharge_selected.png", }, { "text": "车队", "iconPath": "/images/market.png", "selectedIconPath": "/images/market_selected.png", } ] }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.tabComponent = this.selectComponent('#tabComponent'); let selectedColor = this.data.selectedColor; let color = this.data.color; this.tabComponent.setData({ selectedColor: selectedColor, color:color }) console.log(this.tabComponent.data.tabbarIndex) }, //获取组件传递出来的数据 tabChange:function(e){ let index = e.detail.tabbarIndex; this.setData({ tabbarIndex:index }) console.log(e.detail.tabbarIndex) }})
到此,关于"小程序怎么自定义tabBar组件封装"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!
组件
页面
程序
封装
内容
结构
学习
事件
代码
元素
数据
方法
更多
帮助
实用
接下来
下标
函数
名称
周期
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
重庆市网络安全周
国泰安数据库说明附录在哪
mysql配置数据库
数据库日期精度
网络安全诈骗内容
中国互联网科技的机遇
网络安全问题u盘问题处理结果
java的数据库
镇江专业软件开发哪家好
数据库管理员的职业素质
w7系统数据库几位
周村化工软件开发报价
荆门租房软件开发
每一台电脑都有数据库管理系统吗
工信部数据库应用工程师证
pg数据库导出入
网络安全专升硕
沈阳方林装修软件开发
数据库标准征求意见
批量管理服务器应用
网易猫和老鼠手游服务器账号
西安的网络安全专业好就业吗
要怎么才能吧默认数据库
实用网络技术期末试卷
计算机网络技术主要课题
中国网络安全警察
高一选修网络技术ppt
c 图像保存在数据库
数据库建多少表
柳州网络安全课程免费试学