uniapp开发小程序-实现中间凸起的 tabbar

chatgpt/2023/9/24 2:07:29

一、效果展示:

在这里插入图片描述

二、代码实现:

1.首先在pages.json文件中进行tabbar的样式和列表配置,代码如下:

{"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages{"path": "pages/index/index","style": {"navigationBarTitleText": "uni-app"}},{"path": "pages/todo/todo","style": {"navigationBarTitleText": "uni-app"}},{"path": "pages/workBench/workBench","style": {"navigationBarTitleText": "uni-app"}},{"path": "pages/contacts/contacts","style": {"navigationBarTitleText": "uni-app"}},{"path": "pages/my/my","style": {"navigationBarTitleText": "uni-app"}}],"tabBar": {"color": "#B6C3D2","selectedColor": "#2B2E3D","borderStyle": "black","backgroundColor": "#FFFFFF","list": [{"pagePath": "pages/index/index","iconPath": "static/index01.png","selectedIconPath": "static/index02.png","text": "首页"},{"pagePath": "pages/todo/todo","iconPath": "static/dd01.png","selectedIconPath": "static/dd02.png","text": "订单1"},{"pagePath": "pages/workBench/workBench","iconPath": "static/shop01.png","selectedIconPath": "static/shop02.png","text": "店铺"},{"pagePath": "pages/contacts/contacts","iconPath": "static/dd01.png","selectedIconPath": "static/dd02.png","text": "订单2"},{"pagePath": "pages/my/my","iconPath": "static/my01.png","selectedIconPath": "static/my02.png","text": "我的"}]},"globalStyle": {"navigationBarTextStyle": "black","navigationBarTitleText": "uni-app","navigationBarBackgroundColor": "#F8F8F8","backgroundColor": "#F8F8F8"},"uniIdRouter": {}
}

2.在components文件中封装一个Tabbar 组件,命名为TabBar.vue 代码如下:

<template><view class="tabbar-container"><block><view class="tabbar-item" v-for="(item,index) in tabbarList":class="[item.centerItem ? ' center-item' : '']" @click="changeItem(item)"><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>export default {props: {currentPage: {type: Number,default: 0}},data() {return {currentItem: 0,tabbarList: [{id: 0,path: "/pages/index/index",icon: "/static/index01.png",selectIcon: "/static/index02.png",text: "首页",centerItem: false}, {id: 1,path: "/pages/todo/todo",icon: "/static/dd01.png",selectIcon: "/static/dd02.png",text: "订单1",centerItem: false}, {id: 2,path: "/pages/workBench/workBench",icon: "/static/shop01.png",selectIcon: "/static/shop02.png",text: "店铺",centerItem: true}, {id: 3,path: "/pages/contacts/contacts",icon: "/static/dd01.png",selectIcon: "/static/dd02.png",text: "订单2",centerItem: false}, {id: 4,path: "/pages/mine/mine",icon: "/static/my01.png",selectIcon: "/static/my02.png",text: "我的",centerItem: false}]};},mounted() {this.currentItem = this.currentPage;uni.hideTabBar();},methods: {changeItem(item) {let _this = this;//_this.currentItem = item.id;  uni.switchTab({url: item.path});console.log(item.path)}}}
</script>
<style>view {padding: 0;margin: 0;box-sizing: border-box;}.tabbar-container {position: fixed;bottom: 0;left: 0;width: 100%;height: 110rpx;/* box-shadow: 0 0 5px #999;  */box-shadow: 0px 3px 20px rgba(0, 0, 0, 0.16);border-top: 1px;display: flex;align-items: center;padding: 5rpx 0;color: #999999;z-index: 200;background-color: #fff;}.tabbar-container .tabbar-item {width: 20%;height: 100rpx;display: flex;flex-direction: column;justify-content: center;align-items: center;text-align: center;}.tabbar-container .item-active {color: #1AD080;}.tabbar-container .center-item {display: block;position: relative;}.tabbar-container .tabbar-item .item-top {width: 54rpx;height: 54rpx;padding: 0rpx;}.tabbar-container .center-item .item-top {flex-shrink: 0;width: 100rpx;height: 100rpx;position: absolute;top: -50rpx;left: calc(50% - 50rpx);border-radius: 50%;box-shadow: 0px 3px 20px rgba(0, 0, 0, 0.16);/* box-shadow: 0 0 5px #999;  */background-color: #ffffff;padding: 10rpx;}.tabbar-container .tabbar-item .item-top image {width: 100%;height: 100%;}tabbar-container .tabbar-item:nth-child(3) .item-top image {background: #ff0000;}.tabbar-container .tabbar-item .item-bottom {font-size: 28rpx;width: 100%;}.tabbar-container .center-item .item-bottom {position: absolute;bottom: 5rpx;}
</style>

3.在mian.js 全局注册组件

import TabBar from "./components/TabBar.vue"
Vue.component('TabBar', TabBar);  

4.在页面中使用组件

<TabBar :current-page="0" />

完成~

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

如若内容造成侵权/违法违规/事实不符,请联系郑州代理记账网进行投诉反馈,一经查实,立即删除!

相关文章

Python异步请求:异步编程的常见问题

Python异步请求&#xff1a;异步编程的常见问题 异步编程的常见问题 在异步编程过程中&#xff0c;可能会遇到一些常见的问题。了解这些问题并掌握解决方法对于开发高效的异步应用程序至关重要。 异常处理 在异步编程中&#xff0c;异常处理变得更加关键。在同步编程中&…

深度学习,神经网络介绍

目录 1.神经网络的整体构架 2.神经网络架构细节 3.正则化与激活函数 4.神经网络过拟合解决方法 1.神经网络的整体构架 ConvNetJS demo: Classify toy 2D data 我们可以看看这个神经网络的网站&#xff0c;可以用来学习。 神经网络的整体构架如下1&#xff1a; 感知器&…

计算机毕设 深度学习实现行人重识别 - python opencv yolo Reid

文章目录 0 前言1 课题背景2 效果展示3 行人检测4 行人重识别5 其他工具6 最后 0 前言 &#x1f525; 这两年开始毕业设计和毕业答辩的要求和难度不断提升&#xff0c;传统的毕设题目缺少创新和亮点&#xff0c;往往达不到毕业答辩的要求&#xff0c;这两年不断有学弟学妹告诉…

AD21 PCB设计的高级应用(七)盲埋孔的设置

&#xff08;七&#xff09;盲埋孔的设置 1.盲埋孔的设置2.Pad/Via模板的使用 1.盲埋孔的设置 随着目前便携式产品的设计朝着小型化和高密度的方向发展,PCB的设计难度也越来越大,对 PCB 的生产工艺提出了更高的要求。在目前大部分的便携式产品中 0.65mm间距以下 BGA封装均使用…

[TWAS]individual-level implementation of PrediXcan(实现PrediXcan)

引言 在下文中&#xff0c;我们将重点讨论PrediXcan的个人级实现。 该方法最初是在这个存储库中实现的。但是&#xff0c;维护和新特性很难实现&#xff0c;因此我们重新实现了该方法&#xff0c;以便与最新的MetaXcan特性集成。 PrediXcan包括两个步骤: 在具有可用基因型的队…

AcWing110. 防晒

输入样例&#xff1a; 3 2 3 10 2 5 1 5 6 2 4 1输出样例&#xff1a; 2 解析&#xff1a; 按照右区间排序&#xff0c;优先满足小的。 #include<bits/stdc.h> using namespace std; typedef long long ll; const int N3000; int n,m,cnt[N],x,y,res; struct node{int…

canvas基础使用1【入门教程】

一、介绍 canvas 是 HTML5 新增的一个标签&#xff0c;表示画布 <canvas></canvas> canvas 也是 HTML5 的画布技术&#xff0c;可以通过编码的方式在画布上描绘图像 <html><head>...</head><body><canvas></canvas></bod…

【雕爷学编程】MicroPython动手做(25)——语音合成与语音识别2

知识点&#xff1a;什么是掌控板&#xff1f; 掌控板是一块普及STEAM创客教育、人工智能教育、机器人编程教育的开源智能硬件。它集成ESP-32高性能双核芯片&#xff0c;支持WiFi和蓝牙双模通信&#xff0c;可作为物联网节点&#xff0c;实现物联网应用。同时掌控板上集成了OLED…
推荐文章