uview2.0自定义tabbar

tabbar组件

javascript 复制代码
<template>
	<u-tabbar :value="tab" @change="changeTab" :fixed="true" :border="true" :placeholder="true"
		:safeAreaInsetBottom="true">
		<u-tabbar-item text="消息" icon="chat" badge="3"></u-tabbar-item>
		<u-tabbar-item text="">
			<image style="width: 80rpx;height: 80rpx;" slot="active-icon" src="../static/wallet.png"></image>
			<image style="width: 80rpx;height: 80rpx;" slot="inactive-icon" src="../static/wallet.png"></image>
		</u-tabbar-item>
		<u-tabbar-item text="设置" icon="setting"></u-tabbar-item>
	</u-tabbar>
</template>

<script>
	export default {
		props: {
			tab: {
				type: Number,
				require: true
			},
		},
		data() {
			return {
				list: ["/pages/message/index", '/pages/home/index', "/pages/set/index"]
			}
		},
		methods: {
			changeTab(name) {
				console.log(88, name)
				uni.reLaunch({
					url: this.list[name]
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
	}
</style>

main.js全局组件注册

javascript 复制代码
import tabbar from './components/tabbar.vue'
Vue.component('tabbar', tabbar)

主页面使用

  • 在三个主页面分别引入组件
  • 传入对于的索引即可
javascript 复制代码
<!-- 自定义底部-->
<tabbar :tab="1"></tabbar>
相关推荐
智商不够_熬夜来凑15 分钟前
【Radio & Checkbox】
前端·javascript·vue.js
xiaofeichaichai24 分钟前
Diff 算法
前端·javascript
Larcher35 分钟前
从 0 到 1:用 Bun + axios 快速搭建 LLM API 客户端
前端·javascript
子午38 分钟前
基于DeepSeek的酒店客房管理系统~Python+DeepSeek智能问答+Vue3+Web网站系统
开发语言·前端·python
bkspiderx39 分钟前
Boa Web服务器HTTPS支持的源码改造方案
服务器·前端·https·web服务器·boa·https支持
贺今宵1 小时前
Vue 3 + Capacitor 使用jeep-sqlite,web端使用本地sqlite数据库
前端·数据库·vue.js·sqlite·web
taocarts_bidfans1 小时前
Google Indexing API 外贸独立站主动推送收录实战开发
前端·独立站·外贸独立站·taoify
lichenyang4531 小时前
鸿蒙 Stage 模型到底是什么?一篇讲清 Ability、EntryAbility 和入口文件为什么这么设计
前端
ihuyigui1 小时前
国际商超零售短信接口
大数据·前端·后端·架构·零售
Yan-英杰1 小时前
从零玩转搜索引擎 API: 多引擎整合实战
服务器·前端·microsoft