Skip to content

Tabbar (底部导航)

页面切换底部菜单

支持平台

安卓ios鸿蒙web微信小程序

示例代码

html
<template>
	<t-page main-class="p-30">
		<t-card main-class="tdr tdb mb-30" title='Tabbar 底部导航' sub-title="页面切换底部菜单"></t-card>
		<t-section title='使用图片' main-class="tdr tdb mb-30"></t-section>
		<t-tabbar main-class="tdr tdb mb-30" @change="onchange">
			<template v-slot:default="{current,type}">
				<t-row>
					<t-tabbar-item v-for="(item,index) in tabList2" :key="index">
						<t-icon :name="current.toString()==index.toString()?item.activeIcon:item.inactiveIcon"
							main-class="s-45"></t-icon>
						<t-text :type="current.toString()==index.toString()?type:'info'" :text="item.label"
							main-class="mt-5"></t-text>
					</t-tabbar-item>
				</t-row>
			</template>
		</t-tabbar>
		<t-section title='使用图标+切换主题' main-class="tdr tdb mb-30">
		</t-section>
		<t-tabbar type='e' main-class="df dlrb-0 bt-1px,s,#ccc ov" @change="onchange">
			<template v-slot:default="{current,type}">
				<t-row main-class="ov">
					<t-tabbar-item v-for="(item,index) in tabList" :key="index">
						<t-col main-class="fc dr ov">
							<t-icon :type="current.toString()==index.toString()?type:'info'"
								:name="current.toString()==index.toString()?item.activeIcon:item.inactiveIcon"
								main-class="s-45"></t-icon>
							<t-text :type="current.toString()==index.toString()?type:'info'" :text="item.label"
								main-class="mt-5"></t-text>
							<t-badge v-if="item.badgeValue>0" type="error" main-class="da dl-50 dt-n5"
								:text="`${item.badgeValue}`"></t-badge>
						</t-col>
					</t-tabbar-item>
				</t-row>
			</template>
		</t-tabbar>
	</t-page>
</template>

<script>
	type tabbarOptions = {
		activeIcon : string
		inactiveIcon : string
		raised : boolean
		label : string
		badgeValue : number
	}
	export default {
		data() {
			return {
				iconsrc: "email-fill",
				current: 0,
				tabList2: [{
					activeIcon: '/static/tabbar/ui1.png',
					inactiveIcon: '/static/tabbar/ui.png',
					raised: false,
					label: 'UI',
					badgeValue: 0
				},
				{
					activeIcon: '/static/tabbar/table1.png',
					inactiveIcon: '/static/tabbar/table.png',
					raised: false,
					label: '图表',
					badgeValue: 9999

				},
				{
					activeIcon: '/static/tabbar/api1.png',
					inactiveIcon: '/static/tabbar/api.png',
					raised: true,
					label: '插件',
					badgeValue: 1
				},
				{
					activeIcon: '/static/tabbar/template1.png',
					inactiveIcon: '/static/tabbar/template.png',
					raised: false,
					label: '模版',
					badgeValue: 0
				},
				{
					activeIcon: '/static/tabbar/my1.png',
					inactiveIcon: '/static/tabbar/my.png',
					raised: false,
					label: '我的',
					badgeValue: 0
				}] as tabbarOptions[],
				tabList1: [{
					activeIcon: '/static/tabbar/home_s.png',
					inactiveIcon: '/static/tabbar/home.png',
					raised: false,
					label: '首页',
					badgeValue: 0
				},
				{
					activeIcon: '/static/tabbar/find_s.png',
					inactiveIcon: '/static/tabbar/find.png',
					raised: false,
					label: '发现',
					badgeValue: 9999

				},
				{
					activeIcon: 'home-fill',
					inactiveIcon: 'home',
					raised: false,
					label: '购物车',
					badgeValue: 1
				},
				{
					activeIcon: '/static/tabbar/msg_s.png',
					inactiveIcon: '/static/tabbar/msg.png',
					raised: false,
					label: '消息',
					badgeValue: 0
				},
				{
					activeIcon: '/static/tabbar/me_s.png',
					inactiveIcon: '/static/tabbar/me.png',
					raised: false,
					label: '我的',
					badgeValue: 0
				}] as tabbarOptions[],
				tabList: [{
					activeIcon: 'home-fill',
					inactiveIcon: 'home',
					raised: false,
					label: '首页',
					badgeValue: 0
				},
				{
					activeIcon: 'play-circle-fill',
					inactiveIcon: 'play-circle',
					raised: false,
					label: '发现',
					badgeValue: 9999

				},
				{
					activeIcon: 'bag-fill',
					inactiveIcon: 'bag',
					raised: false,
					label: '购物车',
					badgeValue: 1
				},
				{
					activeIcon: 'email-fill',
					inactiveIcon: 'email',
					raised: false,
					label: '消息',
					badgeValue: 0
				},
				{
					activeIcon: 'rmb-circle-fill',
					inactiveIcon: 'rmb-circle',
					raised: false,
					label: '我的',
					badgeValue: 0
				}] as tabbarOptions[]
			};
		},
		methods: {
			onchange(e : number) {
				console.log(e)
			},
			tabBarClick(index : number) {
				this.current = index
			}
		}
	}
</script>

属性

名称类型默认值说明可选值
sizeStringmini组件尺寸large(大尺寸), medium(中尺寸), small(小尺寸), mini(迷你)
typeString""组件类型info(信息), primary(正常), error(错误), warning(警告), success(成功)
disabledBooleanfalse组件是否禁用false, true
stopBooleanfalse是否阻止事件冒泡(Tui统一写法处理事件冒泡)false, true
hoverBooleantrue是否有点击效果false, true
pathString""点击组件后跳转的页面路径,如果为空则响应点击事件,如果不为空则跳转页面不会响应单击事件。-
mainClassString""组件根节点的样式-
nativeClassString""组件根节点原生样式-
effectString"normal"组件显示主题normal(正常), dark(深色), light(浅色), plain(镂空)
currentNumber1当前页索引
typeStringp

事件

名称返回参数说明
change--

插槽

名称返回值说明
default-