当前位置: 首页 > news >正文

零基础学习做网站蚌埠做网站建设费用

零基础学习做网站,蚌埠做网站建设费用,个人网站开发与设计摘要,百度推广找谁发现微信小程序自带导航栏有些丑,只能改变一下常用图标字体颜色什么的,今天就搞个自定义的tab,效果如下。一,首先就是配置pages.json文件,必须设置"custom": true, // 关键配置:启用自定义 tabB…

发现微信小程序自带导航栏有些丑,只能改变一下常用图标字体颜色什么的,今天就搞个自定义的tab,效果如下。

一,首先就是配置pages.json文件,必须设置"custom": true,  // 关键配置:启用自定义 tabBar

"list" 里面还是和自带的一样,开始研究设置为空[] 但是运行不起来,提示必须得有之前哪些tab信息。

这是我的测试代码

"tabBar" : {"custom": true,  // 关键配置:启用自定义 tabBar"list" : [{"selectedIconPath" : "static/icons/home-active.png","iconPath" : "static/icons/home.png","pagePath" : "pages/index/index","text" : "首页"},{"selectedIconPath" : "static/icons/add-active.png","iconPath" : "static/icons/add.png","pagePath" : "pages/add/index","text" : "记账"},{"selectedIconPath" : "static/icons/analysis-active.png","iconPath" : "static/icons/analysis.png","pagePath" : "pages/analysis/index","text" : "分析"},{ "selectedIconPath" : "static/icons/mine-active.png","iconPath" : "static/icons/mine.png","pagePath" : "pages/mine/index","text" : "我的"}]}

二、设置 公用 tab 导航页面,新建 components--------custom-tabbar目录 及custom-tabbar.vue文件页面

custom-tabbar.vue 

<template><view class="custom-tabbar"><view class="tabbar-item" v-for="(item, index) in tabList" :key="index"@click="switchTab(item.path)"><!-- 图标 --><view class="icon-wrapper"><image :src="currentPath === item.path ? item.selectedIcon : item.icon" mode="widthFix"class="tabbar-icon"></image></view><!-- 文字 --><text class="tabbar-text":class="{ 'active': currentPath === item.path }">{{ item.text }}</text></view></view>
</template><script>
export default {data() {return {currentPath: '',  // 当前页面路径// 导航栏配置tabList: [{path: '/pages/index/index',text: '首页',icon: '/static/icons/home.png',selectedIcon: '/static/icons/home-active.png'},{path: '/pages/add/index',text: '记账',icon: '/static/icons/add.png',selectedIcon: '/static/icons/add-active.png'},{path: '/pages/analysis/index',text: '分析',icon: '/static/icons/analysis.png',selectedIcon: '/static/icons/analysis-active.png'},{path: '/pages/mine/index',text: '我的',icon: '/static/icons/mine.png',selectedIcon: '/static/icons/mine-active.png'}]}},
created() {// 监听全局路由变化this.routeListener = uni.onAppRoute((res) => {// 路由变化后,延迟获取页面栈(确保页面已切换完成)setTimeout(() => {const pages = getCurrentPages()this.currentPath = "/" + pages[pages.length - 1].routeconsole.log('路由变化,更新路径:', this.currentPath)}, 100)})},beforeDestroy() {// 销毁时移除监听,避免内存泄漏this.routeListener()},methods: {// 切换页面switchTab(path) {// 如果点击的是当前页面,不做操作if (this.currentPath === path) return// 使用 switchTab 跳转(适合 tab 页面)uni.switchTab({url: path})}}
}
</script><style scoped>
.custom-tabbar {display: flex;justify-content: space-around;align-items: center;position: fixed;bottom: 3%;left: 2%;right: 2%;height: 50px;border-radius: 25px;box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);z-index: 999;background: #fff;
}.tabbar-item {display: flex;flex-direction: column;align-items: center;justify-content: center;flex: 1;
}.icon-wrapper {height: 24px;margin-bottom: 2px;
}.tabbar-icon {width: 24px;height: 24px;
}.tabbar-text {font-size: 12px;color: #2c2c2c;
}.tabbar-text.active {color: #007aff;  /* 选中状态颜色 */
}
</style>

三、引用到所需要的页面即可,举例:index.vue

1,页面部分

<template><view class="container"><!-- 页面内容 --><custom-tabbar></custom-tabbar></view>
</template>

2,js 部分:设置引入页面路径,

<script>
import customTabbar from '@/components/custom-tabbar/custom-tabbar.vue'
export default {components: {customTabbar} 
}
</script>

3,css 部分

.container {padding-bottom: 50px;/* 适配安全区 */padding-bottom: calc(50px + constant(safe-area-inset-bottom));padding-bottom: calc(50px + env(safe-area-inset-bottom));
}

基本完事,可以试试了。

http://www.dtcms.com/a/439221.html

相关文章:

  • 麒麟系统安装后添加自启动
  • 网站底部备案号悬挂佛山木工机械厂骏域网站建设专家
  • 顺序表专题
  • 网站 备案 中国 名字微网站模板代码
  • ASP.NET Core Web API 中控制器操作的返回类型及Swagger
  • AI模型测评平台工程化实战十二讲(第六讲:大模型测评系统:智能模型管理模块的设计与实现)
  • 手写MyBatis第90弹:动态SQL测试策略与验证方法
  • 比较有名的公司网站网站建设犀牛云
  • 网站备案 企业备案响应式博客wordpress
  • AI 重塑实体经济:2025 传统产业转型的南通实践启示
  • 番禺建设网站平台网站建设所需要的内容
  • 网站每年续费费用南通制作网站
  • 特优项目网站建设方案辽宁建设工程信息网开评标系统
  • 哪个网站可以做验证码兼职强 的软件免费的软件下载
  • IPV4/Ipv6公网检测网站, DDNS配置
  • 贵州省城乡和住房建设厅网站线上app怎么做
  • 地方网站推广云主机费用
  • QT肝8天13--删除用户
  • 素材分享网站源码北龙中网 可信网站验证 费用
  • P7226 [COCI 2015/2016 #3] POT
  • 网店代运营网站建设银行信用卡积分兑换话费网站
  • 数字资产离婚分割案:巨额数字资产归谁所有?
  • 网站源码安装教程阳江房产网站
  • 2.VMware上的Kali Linux操作系统安装(2025年10月3日)
  • 全志T113-S3开发板遇到的问题
  • 神卓云监控 K900:异地监控技术落地与方案优化实践
  • 东莞企业网站排名wordpress重置后密码是多少
  • 设计网站建设网站美化教程下载
  • 队列算法精讲:从栈与队列互实现到循环队列(待补充)
  • 蝴蝶优化算法:原理、改进与应用