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>
相关推荐
^小桃冰茶2 小时前
CSS知识总结
前端·css
巴巴_羊3 小时前
yarn npm pnpm
前端·npm·node.js
chéng ௹5 小时前
vue2 上传pdf,拖拽盖章,下载图片
前端·css·pdf
嗯.~5 小时前
【无标题】如何在sheel中运行Spark
前端·javascript·c#
A_aspectJ8 小时前
【Bootstrap V4系列】学习入门教程之 组件-输入组(Input group)
前端·css·学习·bootstrap·html
兆。8 小时前
电子商城后台管理平台-Flask Vue项目开发
前端·vue.js·后端·python·flask
互联网搬砖老肖8 小时前
Web 架构之负载均衡全解析
前端·架构·负载均衡
sunbyte9 小时前
Tailwind CSS v4 主题化实践入门(自定义 Theme + 主题模式切换)✨
前端·javascript·css·tailwindcss
湛海不过深蓝10 小时前
【css】css统一设置变量
前端·css
程序员的世界你不懂10 小时前
tomcat6性能优化
前端·性能优化·firefox