Drawer
组件类型:UxDrawerComponentPublicInstance
支持点击、触摸滑动打开关闭
平台兼容性
UniApp X
Android | iOS | web | 鸿蒙 Next | 小程序 |
---|---|---|---|---|
√ | √ | √ | x | √ |
UniApp Vue Nvue
Android | iOS | web | 鸿蒙 Next | 小程序 |
---|---|---|---|---|
x | x | √ | x | x |
Props
属性名 | 类型 | 默认值 | 说明 |
---|---|---|---|
drawer | Slot | 侧边栏内容插槽 | |
touchable | Boolean | true | 触摸拖动 |
direction | String | right | 方向 |
fixed | Boolean | false | 固定定位 |
width | String | 85% | 宽度 |
height | String | 40% | 高度 |
background | String | transparent | 背景色 |
border | Boolean | false | 显示边框 |
opacity | Number | $ux.Conf.maskAlpha | 遮罩透明度0-1 |
duration | Number | 300ms | 过渡时间 |
showBlur | Boolean | false | 开启模糊背景 |
blurRadius | Number | 10 | 模糊半径 |
blurColor | String | rgba(10,10,10,0.3) | 模糊颜色 |
zIndex | Number | 20000 | 层级z-index |
maskClose | Boolean | true | 遮罩层关闭 |
interceptBack | Boolean | false | 拦截页面返回 |
disabled | Boolean | false | 是否禁用 |
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>