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>
相关推荐
刘卓航众创芯云服务部36 分钟前
Kimi K3复杂任务实测:我把团队最头疼的三个场景全跑了一遍
前端
cll_8692418911 小时前
一个好看的Wordpress博客文字css样式
前端·css·ui
武子康1 小时前
Shippy:确定性工具、会话级 Sandbox 与 Live-Data Eval(4 类收敛 + 7 步实现方案 + 6 类评测指标)
前端·人工智能·后端
糖果店的幽灵1 小时前
langgraph分支之 - 动态分支(Dynamic Branch)
java·前端·javascript·人工智能·langgraph
meilindehuzi_a1 小时前
Workflow 与 Agent 有什么区别:从 LangChain 流水线到智能体决策
前端·人工智能
三翼鸟数字化技术团队1 小时前
一种前端大屏适配方案
前端·css
小四的小六2 小时前
WebView 在 AI 时代的三个被低估的价值——从自己的 AI 产品里找到的答案
前端·openai·ai编程
程序员黑豆2 小时前
鸿蒙应用开发:ForEach 循环渲染用法详解
前端·harmonyos
JarvanMo2 小时前
HTTP 迎来 16 年来首个全新请求方法:`QUERY`
前端
亿元程序员2 小时前
90%的Cocos开发者不知道,插件还能这么玩!
前端