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

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

一、效果展示:

在这里插入图片描述

二、代码实现:

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.lryc.cn/news/105183.html

相关文章:

  • Vue引入与Vue拦截原理
  • 2023年电赛---运动目标控制与自动追踪系统(E题)OpenMV方案
  • 6G内存运行Llama2-Chinese-7B-chat模型
  • 项目经理必备-项目总体计划模板-制式文件,可直接填写使用-公司可用
  • 正则表达式系列|(以xx开头xx结尾提取、切分、替换)
  • 金融学复习博迪(第1-5章)
  • 【前端知识】React 基础巩固(三十七)——自定义connect高阶组件
  • 前端PDF导出,使用html2Canvas和jsPDF插件
  • Android 设备兼容性使用详解
  • vnc加固
  • Windows下Nginx安装与配置教程
  • Iterator迭代器和Generator生成器
  • Modbus-RTU协议C#实现
  • Redis学习---大数据技术之Redis(NoSQL简介、Redis简介、Redis安装、五大数据类型、相关配置、持久化)
  • 基于组合双向拍卖的共享储能机制研究(Matlab代码实现)
  • 服务机器人有哪些品类
  • 3.netty和protobuf
  • NLP实践——Llama-2 多轮对话prompt构建
  • 《TCP IP网络编程》第十四章
  • 网络基础-认识每层的设备和每层的特点用途
  • 【Linux操作系统】深入解析Linux定时任务调度机制-cronat指令
  • 动手学深度学习(一)预备知识
  • item_get-KS-获取商品详情
  • [华为OD] 最小传输时延(dijkstra算法)
  • 问道管理:总资产大于总市值好吗?
  • IBM Spectrum LSF (“LSF“ ,简称为负载共享设施) 用户案例
  • Pytorch深度学习-----神经网络之非线性激活的使用(ReLu、Sigmoid)
  • Gis入门,使用起止点和两个控制点生成三阶贝塞尔曲线(共四个控制点,线段转曲线)
  • Web-7-深入理解Cookie与Session:实现用户跟踪和数据存储
  • Springboot设置Https