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>
相关推荐
渔_6 分钟前
uni-app 图片预览 + 长按保存,超实用!
前端
八哥程序员6 分钟前
从DOM结构到布局流:display: content的深度解析与实战应用
前端·css
Shaneyxs6 分钟前
从 0 到 1 实现CloudBase云开发 + 低代码全栈开发活动管理小程序(07)
前端
Shaneyxs8 分钟前
从 0 到 1 实现CloudBase云开发 + 低代码全栈开发活动管理小程序(10)
前端
Shaneyxs9 分钟前
从 0 到 1 实现CloudBase云开发 + 低代码全栈开发活动管理小程序(05)
前端
Shaneyxs12 分钟前
从 0 到 1 实现CloudBase云开发 + 低代码全栈开发活动管理小程序(08)
前端
掘金一周15 分钟前
【用户行为监控】别只做工具人了!手把手带你写一个前端埋点统计 SDK | 掘金一周 12.18
前端·人工智能·后端
前端 贾公子35 分钟前
Eruda:移动端网页调试利器
前端·javascript·vue.js
Hashan1 小时前
Elpis:抽离业务代码,发布NPM包
前端·javascript·vue.js