Skip to content
本页导读

Drawer

组件类型:UxDrawerComponentPublicInstance

支持点击、触摸滑动打开关闭

平台兼容性

UniApp X

AndroidiOSweb鸿蒙 Next小程序
x

UniApp Vue Nvue

AndroidiOSweb鸿蒙 Next小程序
xxxx

Props

属性名类型默认值说明
drawerSlot侧边栏内容插槽
touchableBooleantrue触摸拖动
directionStringright方向
fixedBooleanfalse固定定位
widthString85%宽度
heightString40%高度
backgroundStringtransparent背景色
borderBooleanfalse显示边框
opacityNumber$ux.Conf.maskAlpha遮罩透明度0-1
durationNumber300ms过渡时间
showBlurBooleanfalse开启模糊背景
blurRadiusNumber10模糊半径
blurColorStringrgba(10,10,10,0.3)模糊颜色
zIndexNumber20000层级z-index
maskCloseBooleantrue遮罩层关闭
interceptBackBooleanfalse拦截页面返回
disabledBooleanfalse是否禁用

direction

说明
top向上
right向右
bottom向下
left向左

Events

事件名说明参数
change状态改变时触发
close关闭时触发

示例代码

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-scroll>
			
			<ux-card direction="column" icon="flag-filled" title="抽屉" :bold="true">
				<ux-text text="支持点击、触摸滑动打开关闭"></ux-text>
			</ux-card>
			
			<ux-text :margin="[20]" text="触摸滑动按钮或点击按钮打开侧边栏" color="red"></ux-text>
			
			<ux-drawer ref="right" direction="right" :intercept-back="true" :touchable="touchable">
				<ux-button :margin="[10, 30]" theme="primary" text="右滑/点击打开左侧边栏" @click="onRight"></ux-button>
				
				<template v-slot:drawer>
					<ux-page :colors="['#f0f0f0']">
						
					</ux-page>
				</template>
			</ux-drawer>
			
			<ux-drawer ref="top" direction="top" :touchable="touchable">
				<ux-button :margin="[10, 30]" theme="primary" text="上滑/点击打开下侧边栏" @click="onTop"></ux-button>
				
				<template v-slot:drawer>
					<ux-page :colors="['#f0f0f0']">
						
					</ux-page>
				</template>
			</ux-drawer>
			
			<ux-drawer ref="left" direction="left" :touchable="touchable">
				<ux-button :margin="[10, 30]" theme="primary" text="左滑/点击打开右侧边栏" @click="onLeft"></ux-button>
				
				<template v-slot:drawer>
					<ux-page :colors="['#f0f0f0']">
						
					</ux-page>
				</template>
			</ux-drawer>
			
			<ux-drawer ref="bottom" direction="bottom" :touchable="touchable">
				<ux-button :margin="[10, 30]" theme="primary" text="下滑/点击打开上侧边栏" @click="onBottom"></ux-button>
				
				<template v-slot:drawer>
					<ux-page :colors="['#f0f0f0']">
						
					</ux-page>
				</template>
			</ux-drawer>
			
			<ux-button :margin="[10, 30]" theme="warning" :text="touchable?'关闭触摸滑动':'打开触摸滑动'" @click="onTouchable"></ux-button>
			
		</ux-scroll>
	</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-scroll>
			
			<ux-card direction="column" icon="flag-filled" title="抽屉" :bold="true">
				<ux-text text="支持点击、触摸滑动打开关闭"></ux-text>
			</ux-card>
			
			<ux-text :margin="[20]" text="触摸滑动按钮或点击按钮打开侧边栏" color="red"></ux-text>
			
			<ux-drawer ref="right" direction="right" :intercept-back="true" :touchable="touchable">
				<ux-button :margin="[10, 30]" theme="primary" text="右滑/点击打开左侧边栏" @click="onRight"></ux-button>
				
				<template v-slot:drawer>
					<ux-page :colors="['#f0f0f0']">
						
					</ux-page>
				</template>
			</ux-drawer>
			
			<ux-drawer ref="top" direction="top" :touchable="touchable">
				<ux-button :margin="[10, 30]" theme="primary" text="上滑/点击打开下侧边栏" @click="onTop"></ux-button>
				
				<template v-slot:drawer>
					<ux-page :colors="['#f0f0f0']">
						
					</ux-page>
				</template>
			</ux-drawer>
			
			<ux-drawer ref="left" direction="left" :touchable="touchable">
				<ux-button :margin="[10, 30]" theme="primary" text="左滑/点击打开右侧边栏" @click="onLeft"></ux-button>
				
				<template v-slot:drawer>
					<ux-page :colors="['#f0f0f0']">
						
					</ux-page>
				</template>
			</ux-drawer>
			
			<ux-drawer ref="bottom" direction="bottom" :touchable="touchable">
				<ux-button :margin="[10, 30]" theme="primary" text="下滑/点击打开上侧边栏" @click="onBottom"></ux-button>
				
				<template v-slot:drawer>
					<ux-page :colors="['#f0f0f0']">
						
					</ux-page>
				</template>
			</ux-drawer>
			
			<ux-button :margin="[10, 30]" theme="warning" :text="touchable?'关闭触摸滑动':'打开触摸滑动'" @click="onTouchable"></ux-button>
			
		</ux-scroll>
	</ux-page>
</template>
ts
<script setup>
	import * as plus from '@/uni_modules/ux-plus'
	
	const title = ref('')
	
	const touchable = ref(true)
	
	const left = ref<UxDrawerComponentPublicInstance | null>(null)
	const right = ref<UxDrawerComponentPublicInstance | null>(null)
	const top = ref<UxDrawerComponentPublicInstance | null>(null)
	const bottom = ref<UxDrawerComponentPublicInstance | null>(null)
	
	const showDoc = ref(false)
	
	function onDoc() {
		plus.openWeb({
			title: '在线文档',
			url: 'https://www.uxframe.cn/component/drawer.html',
			// blur: 1,
			success: () => {
				showDoc.value = true
			},
			complete: () => {
				showDoc.value = false
			}
		})
	}
	
	onLoad((e) => {
		title.value = e['title'] ?? ''
	})
	
	function onTouchable() {
		touchable.value = !touchable.value
	}
	
	function onLeft(e: MouseEvent) {
		left.value?.$callMethod('open')
		e.stopPropagation()
	}
	
	function onRight(e: MouseEvent) {
		right.value?.$callMethod('open')
		e.stopPropagation()
	}
	
	function onTop(e: MouseEvent) {
		top.value?.$callMethod('open')
		e.stopPropagation()
	}
	
	function onBottom(e: MouseEvent) {
		bottom.value?.$callMethod('open')
		e.stopPropagation()
	}
	
</script>
<script setup>
	import * as plus from '@/uni_modules/ux-plus'
	
	const title = ref('')
	
	const touchable = ref(true)
	
	const left = ref<UxDrawerComponentPublicInstance | null>(null)
	const right = ref<UxDrawerComponentPublicInstance | null>(null)
	const top = ref<UxDrawerComponentPublicInstance | null>(null)
	const bottom = ref<UxDrawerComponentPublicInstance | null>(null)
	
	const showDoc = ref(false)
	
	function onDoc() {
		plus.openWeb({
			title: '在线文档',
			url: 'https://www.uxframe.cn/component/drawer.html',
			// blur: 1,
			success: () => {
				showDoc.value = true
			},
			complete: () => {
				showDoc.value = false
			}
		})
	}
	
	onLoad((e) => {
		title.value = e['title'] ?? ''
	})
	
	function onTouchable() {
		touchable.value = !touchable.value
	}
	
	function onLeft(e: MouseEvent) {
		left.value?.$callMethod('open')
		e.stopPropagation()
	}
	
	function onRight(e: MouseEvent) {
		right.value?.$callMethod('open')
		e.stopPropagation()
	}
	
	function onTop(e: MouseEvent) {
		top.value?.$callMethod('open')
		e.stopPropagation()
	}
	
	function onBottom(e: MouseEvent) {
		bottom.value?.$callMethod('open')
		e.stopPropagation()
	}
	
</script>
css
<style lang="scss">
	
</style>
<style lang="scss">
	
</style>