Skip to content

Navbar (导航栏)

自定义导航栏,支持透明背景,渐变背景

支持平台

安卓ios鸿蒙web微信小程序

示例代码

html
<template>
	<t-page>
		<t-navbar :main-class="navbarStyle" title="导航栏" :type="navbarType" @back="leftClick" right-icon="setting"
			@rightClick="rightClick"></t-navbar>
		<t-card main-class="mlrt-30" title="Navbar 导航栏" sub-title="自定义导航栏,支持透明背景,渐变背景"></t-card>
		<t-col main-class="p-30">
			<t-col main-class="tdb tdr mb-30 pt-10">
				<t-section title='尺寸'></t-section>
				<t-row main-class="p-30 fww">
					<t-button type='p' main-class="mrb-15" @click="setNav('')">默认(44px)</t-button>
					<t-button type='p' main-class="mrb-15" @click="setNav('h-38px')">38</t-button>
					<t-button type='p' main-class="mrb-15" @click="setNav('h-88px')">88</t-button>
				</t-row>
			</t-col>
			<t-col main-class="tdb tdr mb-30 pt-10">
				<t-section title='主题背景'></t-section>
				<t-row main-class="p-30 fww fais">
					<t-button type='p' main-class="mrb-15" @click="setType('normal')">normal</t-button>
					<t-button type='p' main-class="mrb-15" @click="setType('info')">info</t-button>
					<t-button type='p' main-class="mrb-15" @click="setType('primary')">primary</t-button>
					<t-button type='p' main-class="mrb-15" @click="setType('error')">error</t-button>
					<t-button type='p' main-class="mrb-15" @click="setType('warning')">warning</t-button>
					<t-button type='p' main-class="mr-15" @click="setType('success')">success</t-button>
				</t-row>
			</t-col>
			<t-col main-class="tdb tdr mb-30 pt-10">
				<t-section title='自定义背景'></t-section>
				<t-row main-class="p-30 fww fais">
					<t-button type='p' main-class="mrb-15" @click="setNav('bg-#00aa7f')">#00aa7f</t-button>
					<t-button type='p' main-class="mrb-15" @click="setNav('bir-blue,red')">渐变</t-button>
					<t-button type='p' main-class="mrb-15" @click="setNav('bg')">透明</t-button>
				</t-row>
			</t-col>
			<t-col main-class="tdr tdb mb-30 pt-10">
				<t-section title='插槽'></t-section>
				<t-navbar type="p" :fixed="false" :placeholder="false" back-view-class="tdb plr-20 ptb-10 r-60 faic">
					<template v-slot:left>
						<t-row main-class="faic">
							<t-icon name="arrow-leftward"></t-icon>
							<t-line direction="column" line-size="5px" main-class="#bcbcbc mlr-20" length="24"></t-line>
							<t-icon name="home-fill" main-class=""></t-icon>
						</t-row>
					</template>
					<template v-slot:center>
						<t-text main-class="c-#fff">插槽定制样式</t-text>
					</template>
					<template v-slot:right>
						<t-icon name="setting" main-class="c-#fff"></t-icon>
					</template>
				</t-navbar>
			</t-col>
		</t-col>
	</t-page>
</template>
<script>
	export default {
		data() {
			return {
				navbarStyle: '',
				navbarType: 'normal'
			}
		},
		methods: {
			leftClick() {
				uni.showToast({
					title: "点击左侧图标"
				})
			},
			rightClick() {
				uni.showToast({
					title: "点击右侧图标"
				})
			},
			setNav(sty : string) {
				this.navbarStyle = sty
			},
			setType(type : string) {
				this.navbarStyle = ''
				this.navbarType = type
			}
		}
	}
</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(镂空)
titleString``导航中间标题文本
titleViewClassString``标题文本盒子的样式
titleClassString``标题文本的样式
backViewClassString``返回按钮盒子的样式
backTextClassString``
rightIconClassString``右侧图标的样式
safeAreaInsetTopBooleantrue是否在顶部使用安全区域嵌入
fixedBooleantrue是否固定定位
backIconStringarrow-left返回按钮的图标
rightIconString``右侧图标
showBackBooleantrue是否显示返回按钮
backIconClassString``返回按钮图标的样式
rightViewClassString``右侧容器盒子的样式
rightTextClassString``右侧文字的样式
placeholderBooleantrue是否占位防止塌陷
borderBooleanfalse是否显示边框
backTextString``返回按钮的文本
rightTextString``右侧文本
autoBackBooleantrue是否自动处理返回动作

事件

名称返回参数说明
rightClick-当点击右侧区域时触发
back-当点击返回按钮时触发

插槽

名称返回值说明
name-