Skip to content
本页导读

Sidebar

组件类型:UxSidebarComponentPublicInstance

支持滑动距离自动切换到锚点

平台兼容性

UniApp X

AndroidiOSweb鸿蒙 Next小程序
x

UniApp Vue Nvue

AndroidiOSweb鸿蒙 Next小程序
xxxx

Props

属性名类型默认值说明
defaultSlot默认插槽
themeStringinfo按钮类型
modelValueNumber0双向绑定值
datasUxTab[]sidebar列表
typeStringline类型
animStringscroll动效类型
anchorIdString锚点ScrollId
widthAnyauto宽度
heightAnyauto高度
tabWidthAny100Tab宽度
tabHeightAny44Tab高度
cornerAny0圆角
selectedColorString$ux.Conf.fontColor选中颜色
unselectedColorString$ux.Conf.fontColor未选中颜色
backgroundString$ux.Conf.backgroundColor背景色
backgroundDarkString深色none-不显示,auto-自动适配深色模式,其他-颜色
lineColorString线颜色selectedColor优先级更高
lineWidthAny2线宽度0则自动适配
lineHeightAny30线高度、点直径
fontSizeAny$ux.Conf.fontSize字体大小
selectSizeAny$ux.Conf.fontSize选中字体大小
boldBooleanfalse字体加粗
selectBoldBooleanfalse选中字体加粗
durationNumber300过渡时间
paddingAny12内部padding
offsetAny0锚点偏移距离

theme

说明
text文字
info默认
primary主要
success成功
warning警告
error错误

type

说明
none无
line下划线
point点

anim

说明
none无
scroll左右滚动
push左右推压

backgroundDark

说明
none不显示
auto自动适配深色模式
color其他颜色

Events

事件名说明参数
change当前选择下标改变时触发
anchor当要滚动目标时触发

示例代码

html
<template>
	<ux-page :stack="showDoc">
		<ux-navbar :title="title" :border="false">
			<template v-slot:right>
				<!-- #ifndef MP -->
				<ux-button theme="text" icon="/static/tip.png" :icon-size="22" @click="onDoc()"></ux-button>
				<!-- #endif -->
			</template>
		</ux-navbar>
		
		<ux-card direction="column" icon="flag-filled" title="侧边栏" :bold="true">
			<ux-text text="支持滑动距离自动切换到锚点"></ux-text>
		</ux-card>
		
		<ux-card direction="column" icon="arrowright" title="自动滚动到锚点" :bold="true">
			<ux-sidebar ref="uxSidebarRef" 
				:height="250" 
				anchorId="tabscroll" 
				type="line" 
				theme="success" 
				:font-size="13" 
				:select-size="13" 
				:line-height="0" 
				:corner="5" 
				v-model="tabIndex" 
				:datas="tabs">
				<scroll-view style="height: 250px;" id="tabscroll" direction="vertical" :scroll-with-animation="true" :show-scrollbar="false" @touchstart="presss" @mousedown="presss" @scroll="scroll">
					<view id="tab1" class="b">
						<text class="text">{{ tabs[0].name }}</text>
					</view>
					<view id="tab2" class="b2">
						<text class="text">{{ tabs[1].name }}</text>
					</view>
					<view id="tab3" class="b">
						<text class="text">{{ tabs[2].name }}</text>
					</view>
					<view id="tab4" class="b2">
						<text class="text">{{ tabs[3].name }}</text>
					</view>
					<view id="tab5" class="b">
						<text class="text">{{ tabs[4].name }}</text>
					</view>
					<view id="tab6" class="b2">
						<text class="text">{{ tabs[5].name }}</text>
					</view>
					<view id="tab7" class="b">
						<text class="text">{{ tabs[6].name }}</text>
					</view>
				</scroll-view>
			</ux-sidebar>
		</ux-card>
		
		<ux-placeholder :height="200">
			<ux-row justify="center" align="center" style="height: 100%;">
				<ux-text prefix-icon="soapbubble-filled" text="真的没有了~"></ux-text>
			</ux-row>
		</ux-placeholder>
	</ux-page>
</template>
<template>
	<ux-page :stack="showDoc">
		<ux-navbar :title="title" :border="false">
			<template v-slot:right>
				<!-- #ifndef MP -->
				<ux-button theme="text" icon="/static/tip.png" :icon-size="22" @click="onDoc()"></ux-button>
				<!-- #endif -->
			</template>
		</ux-navbar>
		
		<ux-card direction="column" icon="flag-filled" title="侧边栏" :bold="true">
			<ux-text text="支持滑动距离自动切换到锚点"></ux-text>
		</ux-card>
		
		<ux-card direction="column" icon="arrowright" title="自动滚动到锚点" :bold="true">
			<ux-sidebar ref="uxSidebarRef" 
				:height="250" 
				anchorId="tabscroll" 
				type="line" 
				theme="success" 
				:font-size="13" 
				:select-size="13" 
				:line-height="0" 
				:corner="5" 
				v-model="tabIndex" 
				:datas="tabs">
				<scroll-view style="height: 250px;" id="tabscroll" direction="vertical" :scroll-with-animation="true" :show-scrollbar="false" @touchstart="presss" @mousedown="presss" @scroll="scroll">
					<view id="tab1" class="b">
						<text class="text">{{ tabs[0].name }}</text>
					</view>
					<view id="tab2" class="b2">
						<text class="text">{{ tabs[1].name }}</text>
					</view>
					<view id="tab3" class="b">
						<text class="text">{{ tabs[2].name }}</text>
					</view>
					<view id="tab4" class="b2">
						<text class="text">{{ tabs[3].name }}</text>
					</view>
					<view id="tab5" class="b">
						<text class="text">{{ tabs[4].name }}</text>
					</view>
					<view id="tab6" class="b2">
						<text class="text">{{ tabs[5].name }}</text>
					</view>
					<view id="tab7" class="b">
						<text class="text">{{ tabs[6].name }}</text>
					</view>
				</scroll-view>
			</ux-sidebar>
		</ux-card>
		
		<ux-placeholder :height="200">
			<ux-row justify="center" align="center" style="height: 100%;">
				<ux-text prefix-icon="soapbubble-filled" text="真的没有了~"></ux-text>
			</ux-row>
		</ux-placeholder>
	</ux-page>
</template>
ts
<script setup>
	
	import * as plus from '@/uni_modules/ux-plus'
	import { $ux, UxTab } from '@/uni_modules/ux-frame'

	const title = ref('')
	
	const tabs = [
		{
			anchorId: 'tab1',
			name: '基础组件',
		},
		{
			anchorId: 'tab2',
			name: '表单组件',
			badge: 10
		},
		{
			anchorId: 'tab3',
			name: '反馈组件',
		},
		{
			anchorId: 'tab4',
			name: '展示组件',
		},
		{
			anchorId: 'tab5',
			name: '导航组件',
			badge: 100,
		},
		{
			anchorId: 'tab6',
			name: '布局组件',
		},
		{
			anchorId: 'tab7',
			name: '其他组件',
		}
	] as UxTab[]
	
	const tabIndex = ref(0)
	const uxSidebarRef = ref<UxSidebarComponentPublicInstance | null>(null)
	
	const isPress = ref(false)
	const showDoc = ref(false)
	
	function onDoc() {
		plus.openWeb({
			title: '在线文档',
			url: 'https://www.uxframe.cn/component/sidebar.html',
			// blur: 1,
			success: () => {
				showDoc.value = true
			},
			complete: () => {
				showDoc.value = false
			}
		})
	}
	
	function presss() {
		isPress.value = true
	}
	
	function scroll(e: ScrollEvent) {
		if(isPress.value) {
			uxSidebarRef.value?.$callMethod('toAnchor', e)
		}
		
		$ux.Util.debounce(() => {
			isPress.value = false
		}, 1000)
	}
	
	onLoad((e) => {
		title.value = e['title'] ?? ''
	})
</script>
<script setup>
	
	import * as plus from '@/uni_modules/ux-plus'
	import { $ux, UxTab } from '@/uni_modules/ux-frame'

	const title = ref('')
	
	const tabs = [
		{
			anchorId: 'tab1',
			name: '基础组件',
		},
		{
			anchorId: 'tab2',
			name: '表单组件',
			badge: 10
		},
		{
			anchorId: 'tab3',
			name: '反馈组件',
		},
		{
			anchorId: 'tab4',
			name: '展示组件',
		},
		{
			anchorId: 'tab5',
			name: '导航组件',
			badge: 100,
		},
		{
			anchorId: 'tab6',
			name: '布局组件',
		},
		{
			anchorId: 'tab7',
			name: '其他组件',
		}
	] as UxTab[]
	
	const tabIndex = ref(0)
	const uxSidebarRef = ref<UxSidebarComponentPublicInstance | null>(null)
	
	const isPress = ref(false)
	const showDoc = ref(false)
	
	function onDoc() {
		plus.openWeb({
			title: '在线文档',
			url: 'https://www.uxframe.cn/component/sidebar.html',
			// blur: 1,
			success: () => {
				showDoc.value = true
			},
			complete: () => {
				showDoc.value = false
			}
		})
	}
	
	function presss() {
		isPress.value = true
	}
	
	function scroll(e: ScrollEvent) {
		if(isPress.value) {
			uxSidebarRef.value?.$callMethod('toAnchor', e)
		}
		
		$ux.Util.debounce(() => {
			isPress.value = false
		}, 1000)
	}
	
	onLoad((e) => {
		title.value = e['title'] ?? ''
	})
</script>
css
<style lang="scss">
	.b {
		width: 100%;
		height: 200px;
		background-color: sandybrown;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		
		.text {
			font-size: 16px;
			color: black;
		}
	}
	
	.b2 {
		@extend .b;
		background-color: skyblue;
	}
</style>
<style lang="scss">
	.b {
		width: 100%;
		height: 200px;
		background-color: sandybrown;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		
		.text {
			font-size: 16px;
			color: black;
		}
	}
	
	.b2 {
		@extend .b;
		background-color: skyblue;
	}
</style>