uni-app 微信小程序之自定义中间圆形tabbar

文章目录

  • [1. 自定义tabbar效果](#1. 自定义tabbar效果)
  • [2. pages新建tabbar页面](#2. pages新建tabbar页面)
  • [3. tabbar 页面结构](#3. tabbar 页面结构)
  • [4. tabbar 页面完整代码](#4. tabbar 页面完整代码)

1. 自定义tabbar效果

2. pages新建tabbar页面

  1. 首先在 pages.json 文件中,新建一个 tabbar 页面
js 复制代码
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
	{
		"path": "pages/index/tabbar",
		"style": {
			"navigationBarTitleText": "tabbar页面",
			"navigationStyle": "custom"
		}
	},
	.....// 其他页面
],

3. tabbar 页面结构

  1. 此页面主要是写 tabbar的html样式和布局,引用主页面代码,通过 v-if 控制进行展示 indexsearchmaimnewsme 一级页面

4. tabbar 页面完整代码

  1. css 样式文件太多了就不贴出来了
html 复制代码
<template>
	<view>
		<index  v-if="PageCur=='index'"></index>
		<search v-if="PageCur=='search'"></search>
		<news v-if="PageCur=='news'"></news>
		<me v-if="PageCur=='me'"></me>
		
		<view class="box">
			<view class="cu-bar tabbar bg-white shadow foot">
				<view class="action" @click="NavChange" data-cur="index">
					<view class='cuIcon-cu-image'>
						<image v-if="PageCur=='index'" src="../../static/tabBar/index_cur.png"></image>
						<image v-if="PageCur != 'index'" src="../../static/tabBar/index.png"></image>
					</view>
					<view :class="PageCur=='index'?'color_main':'text-gray'">首页</view>
				</view>

				<view class="action" @click="NavChange" data-cur="search">
					<view class='cuIcon-cu-image'>
						<view class="cu-tag badge"></view>
						<image v-if="PageCur=='search'" src="../../static/tabBar/shop_cur.png"></image>
						<image v-if="PageCur != 'search'" src="../../static/tabBar/shop.png"></image>
					</view>
					<view :class="PageCur=='search'?'color_main':'text-gray'">会员专区</view>
					
				</view>
<view @click="NavChange" class="action text-gray add-action" data-cur="main">
					<image class="logo_btn" mode="widthFix" src="../../static/logo.png"></image>
					<view :class="PageCur=='main'?'color_main':'text-gray'">组件模板</view>
				</view>

				<view class="action" @click="NavChange" data-cur="news">
					<view class='cuIcon-cu-image'>
						<view class="cu-tag badge">{{message}}</view>
						<image v-if="PageCur=='news'" src="../../static/tabBar/order_cur.png"></image>
						<image v-if="PageCur != 'news'" src="../../static/tabBar/order.png"></image>
					</view>
					<view :class="PageCur=='news'?'color_main':'text-gray'">文章资讯</view>
				</view>

				<view class="action" @click="NavChange" data-cur="me">
					<view class='cuIcon-cu-image'>
						<image v-if="PageCur=='me'" src="../../static/tabBar/me_cur.png"></image>
						<image v-if="PageCur != 'me'" src="../../static/tabBar/me.png"></image>
					</view>
					<view :class="PageCur=='me'?'color_main':'text-gray'">个人中心</view>
				</view>

			</view>
		</view>

	</view>
</template>

<script>
	import index from "./index.vue";	//首页
	import search from "./search.vue";	//会员专区
	import main from "./main.vue";	//组件模板
	import news from "./news.vue";	//文章咨询
	import me from "./me.vue";	//个人中心
	export default {
		components: {
			index,
			search,
			main,
			news,
			me
		},
		data() {
			return {
				PageCur: 'index',
				message: '99+',
				duration:1
			};
		},
		methods: {
			NavChange: function(e) {
				this.PageCur = e.currentTarget.dataset.cur;
			},
		}
	}
</script>

<style lang="scss">
	// 省略
</style>
相关推荐
千寻技术帮19 小时前
50013_基于微信小程序的校园志愿者系统
mysql·微信小程序·springboot·文档·ppt
xiaaaa.z20 小时前
macos HbuildX 使用cli脚本创建uniapp 运行时报错“cli项目运行依赖本地的Nodejs环境,请先安装并配置到系统环境变量后重试。”
macos·uni-app
2501_9159090621 小时前
深入理解HTTPS和HTTP的区别、工作原理及安全重要性
安全·http·ios·小程序·https·uni-app·iphone
汤姆yu21 小时前
基于微信小程序的民宿预定系统
微信小程序·小程序·民宿预定
黑夜世界1 天前
微信小程序map组件聚合簇样式自定义
微信小程序·小程序
qq_12498707531 天前
基于微信小程序的茶叶茶具销售和管理系统(源码+论文+部署+安装)
微服务·微信小程序·小程序·毕业设计
CDwenhuohuo1 天前
微信小程序里用 setData() 修改数据并打印输出 的几种写法
javascript·微信小程序·小程序
小明记账簿2 天前
微信小程序开发实战:图片转 Base64 全解析
微信小程序·小程序
汤姆yu2 天前
基于微信小程序的粤语文化传播系统
微信小程序·小程序
Q_Q5110082852 天前
python+uniapp基于微信小程序的垃圾分类信息系统
spring boot·python·微信小程序·django·flask·uni-app·node.js