uni-app自定义tabBar;uni-app小程序自定义tabBar;uni-app小程序修改中间tabBar导航栏大小;uni-app中间导航栏凸起;uni-app修改底部导航栏

需求:要求小程序,中间的tabBar自定义凸起或者图标变大;
问题:查看uni-app的tabBar文档可知,小程序是不支持midButton的;

解决思路:隐藏uni-app原有的tabBar,然后换成自己手写的导航栏,进行定位和自定义样式;

小程序页面截图:

在这里插入图片描述

H5页面截图:
在这里插入图片描述

步骤和文件结构如下:

在这里插入图片描述

一、pages.json:正常书写,注意H5的需要加上midButton部分

{"pages": [{"path": "pages/index/index","style": {"navigationBarTitleText": "uni-app"}},{"path": "pages/midell/index","style": {"navigationBarTitleText": "midell"}},{"path": "pages/mine/index","style": {"navigationBarTitleText": "mine"}}],"globalStyle": {"navigationBarTextStyle": "black","navigationBarTitleText": "uni-app","navigationBarBackgroundColor": "#F8F8F8","backgroundColor": "#F8F8F8","app-plus": {"background": "#efeff4"}},"tabBar": {"color": "#999999","selectedColor": "#f00","borderStyle": "black","backgroundColor": "#ffffff","midButton": {"text": "中间","pagePath": "pages/midell/index","iconPath": "static/api.png","selectedIconPath": "static/apiHL.png"},"list": [{"pagePath": "pages/index/index","iconPath": "static/template.png","selectedIconPath": "static/templateHL.png","text": "简介"},{"pagePath": "pages/midell/index","iconPath": "static/api.png","selectedIconPath": "static/apiHL.png","text": "中间"},{"pagePath": "pages/mine/index","iconPath": "static/component.png","selectedIconPath": "static/componentHL.png","text": "我的"}]}
}

二、添加公共组件midell-box页面,在里面写上自定义导航栏和样式;(注意:公共组件要符合easycom规范 无需引入直接使用)

逻辑:调用uni.hideTabBar()去除原生导航栏,再根据 centerItem: true ,控制特殊样式

midell-box.vue:可直接复制(注意你的导航栏图片路径)
在这里插入图片描述

<template><view class="tabbar-container"><block><!-- 针对中间的导航栏  通过true来判断控制类名和样式 --><view class="tabbar-item" v-for="(item, index) in tabbarList" :class="[item.centerItem ? 'center-item' : '']" @click="changeItem(item)" :key="index"><view class="item-top"><image :src="currentItem == item.id ? item.selectIcon : item.icon"></image></view><!-- 通过三元判断控制类名 达到控制选中和未选中的样式 --><view class="item-bottom" :class="[currentItem == item.id ? 'item-active' : '']"><text>{{ item.text }}</text></view></view></block></view>
</template><script>
// 组件的书写符合easycom规范 无需引入直接使用
export default {props: {currentPage: {type: Number,default: 0}},data () {return {currentItem: 0,tabbarList: [{id: 0,path: '/pages/index/index',icon: '/static/template.png',selectIcon: '/static/templateHL.png',text: '首页',centerItem: false},{id: 1,path: '/pages/midell/index',icon: '/static/api.png',selectIcon: '/static/apiHL.png',text: '中间',// 通过类名class控制样式大小centerItem: true},{id: 2,path: '/pages/mine/index',icon: '/static/component.png',selectIcon: '/static/componentHL.png',text: '我的',centerItem: false}]}},mounted () {this.currentItem = this.currentPage// 隐藏原来的tabBar导航栏uni.hideTabBar()},methods: {changeItem (item) {let _this = this//_this.currentItem = item.id;uni.switchTab({url: item.path})}}
};
</script>
<style lang="less" scope>
view {padding: 0;margin: 0;box-sizing: border-box;
}
.tabbar-container {position: fixed;bottom: 0rpx;left: 0rpx;width: 100%;height: 110rpx;box-shadow: 0 0 5px #999;display: flex;align-items: center;padding: 5rpx 0;color: #999999;/* 针对tabbar的统一处理 */.tabbar-item {width: 33.33%;height: 100rpx;display: flex;flex-direction: column;justify-content: center;align-items: center;text-align: center;.item-top {width: 70rpx;height: 70rpx;padding: 10rpx;image {width: 100%;height: 100%;}}// 未被选中的导航栏字体.item-bottom {font-size: 28rpx;width: 100%;}// 被选中的导航栏字体.item-active {color: #f00;}}// 最中间的tabbar导航栏.center-item {display: block;position: relative;.item-top {flex-shrink: 0;width: 100rpx;height: 100rpx;position: absolute;top: -50rpx;left: calc(50% - 50rpx);border-radius: 50%;box-shadow: 0 0 5px #999;background-color: rgb(240, 63, 131);}.item-bottom {position: absolute;bottom: 5rpx;}.item-active {position: absolute;bottom: 5rpx;color: #1fff;}}
}
</style>

三、在每个导航栏页面 引入公共组件

<midell-box :current-page="0"></midell-box>

注意current-page的值和公共组件的参数内 id对应
在这里插入图片描述

四、如果想要将中间的按钮,点击弹起二级菜单,可以修改公共组件midell-box,去掉点击中间按钮的path,监听这个点击事件后,打开弹框,在弹框内点击对应的按钮跳转到对应的页面。

下方的中间按钮做了二级菜单弹框,但是点击跳转的页面没写,故没有让其跳转页面,可以自己加。

在这里插入图片描述

点赞收藏吧!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/403587.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

jq localStorage

$(function () {if(!window.localStorage){alert("浏览器不支持localstorage");return false;}else{var storagewindow.localStorage;$(#headerA li).eq(2).addClass(active)}})

c++中BOOL和bool的区别

From: http://blog.csdn.net/zhongguoren666/article/details/8472805 一&#xff1a;在网上找到了BOOL和bool的区别&#xff1a; 1、类型不同 BOOL为int型 bool为布尔型 2、长度不同 bool只有一个字节 BOOL长度视实际环境来定&#xff0c;一般可认为是4个字节 3、取值不同 bo…

常见端口列表

常见端口列表TCP端口7 回显9 丢弃11 在线用户13 时间服务15 网络状态17 每日引用18 消息发送19 字符发生器20 ftp数据21 文件传输22 SSH端口23 远程终端25 发送邮件31 Masters Paradise木马37 时间39 资源定位协议41 DeepThroat木马42 WINS 主机名服务43 Wh…

[JavaScript] DOM操作技术

1. 动态脚本使用<script>元素可以向页面中插入JavaScript代码&#xff0c;一种方式是通过src属性包含外部文件&#xff0c;另一种方式是用这个元素本身来包含代码。动态脚本指在页面加载时不存在&#xff0c;但将来某时通过修改DOM动态添加的脚本。动态加载的外部JavaScr…

uni-app小程序 点击页面滚动到指定位置

uni.pageScrollTo({scrollTop: 0,duration: 300,})

mysql Connector C/C++ 多线程封装

From: http://blog.csdn.net/educast/article/details/14163519 在网上找了好久&#xff0c;有很多封装&#xff0c;但是感觉对多线程处理的不多&#xff0c;都不是很理想。封装完的第一个版本&#xff0c;想法比较简单&#xff0c;使用一个单例模式&#xff0c;对应一个连接&a…

工业控制系统专业术语(不断完善中)

1、DCS &#xff08;Distributed Control System&#xff09;分布式控制系统。主要应用于石油、化工、电力等。2、SCADA (Supervisory Control And Data Acquisition)数据采集与监控&#xff0c;广泛用于电力系统、电气化铁道、风力发电。3、PLC&#xff08; Programmable Logi…

uni-app微信小程序image引入图片;background-image背景图引入图片;小程序预览本地图片;小程序图片过大引入报错;获取本地图片的网络地址;

uni-app小程序图片使用有image标签和background-image背景图两种方式&#xff1a; 下有获取本地图片的网络地址方式&#xff1a;见第四步 一、方式一&#xff1a;使用image标签引入&#xff1a; uni-app官方image 1.官方文档说&#xff1a;src 仅支持相对路径、绝对路径&…

微商小程序加人加粉推广平台二维码

微商加人推广平台丨微商加粉推广平台丨微商拼团丨微商产品推广。

基于MysqlConnector/C++的数据库连接池的实现

From: http://blog.csdn.net/educast/article/details/14164097 1.连接池的介绍&#xff1a; 1.1应用背景&#xff1a; 一般的应用程序都会访问到数据库&#xff0c;在程序访问数据库的时候&#xff0c;每一次数据访问请求都必须经过下面几个步骤&#xff1a;建立数据库连接&a…

【javascript】不刷新页面,实时显示当前时间

这里起主要作用的是setTimeout这个函数。 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns"http://www.w3.org/1999/xhtml"><head>…

PCL Show Point Cloud 显示点云

在使用PCL库的时候&#xff0c;经常需要显示点云&#xff0c;可以用下面这段代码&#xff1a; #include <pcl/visualization/cloud_viewer.h>pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud; pcl::visualization::CloudViewer viewer ("Viewer"); viewer…

css字体自定义,bootstrap自定义字体

<style type"text/css">font-face{font-family:myFont;src:url(/bootstrap-3.3.7-dist/fonts/shishangjianti.ttf);}body{font-family: myFont !important;}</style> .ttf的文件路径根据文件位置定义

cmd连接mysql的方法详解

From: http://www.jb51.net/article/38059.htm 本篇文章是对cmd连接mysql的方法进行了详细的分析介绍&#xff0c;需要的朋友参考下连接&#xff1a;mysql -h主机地址 -u用户名 &#xff0d;p用户密码 &#xff08;注:u与root可以不用加空格&#xff0c;其它也一样&#xff09;…

c/c++多参数的问题

C/C语言有一个不同于其它语言的特性&#xff0c;即其支持可变参数&#xff0c;典型的函数如printf、scanf等可以接受数量不定的参数。如&#xff1a; printf ( "I love you" ); printf ( "%d", a ); printf ( "%d,%d", a, b );第一、二、三个pr…

JS node 后端签名前端文件直传ali-oss解决方案

1&#xff1a;首先打开跨域 上面搞好了开始写代码 html <input type"file" id"upload" onchange"uploadfile()"> js function uploadfile() {var file document.getElementById(upload).files[0]$.ajax({url: /policy,data: ,type: get…

在linux上获得线程id的方法

From: http://www.linuxidc.com/Linux/2014-01/94723.htm 我使用了第二种方法&#xff0c;很方便&#xff1a; #define gettid() syscall(__NR_gettid) 用到的地方 gettid() 在linux2.4版本后&#xff0c;linux使用了NPTL作为自己的线程库&#xff0c;为了兼容POSIX标准&a…

【MCAL】TC397+EB-treso之MCU配置实战 - 芯片时钟

本篇文章介绍了在TC397平台使用EB-treso对MCU驱动模块进行配置的实战过程&#xff0c;主要介绍了后续基本每个外设模块都要涉及的芯片时钟部分&#xff0c;帮助读者了解TC397芯片的时钟树结构&#xff0c;在后续计算配置不同外设模块诸如通信速率&#xff0c;定时器周期等&…