Drawer 抽屉
用于在屏幕边缘显示应用导航等内容的面板。
vue
<template>
<ta-group title="基础用法">
<ta-cell
label="顶部弹出"
isLink
@click="show({ title: '顶部弹出', placement: 'top' })"
></ta-cell>
<ta-cell
label="底部弹出"
isLink
@click="show({ title: '底部弹出', placement: 'bottom' })"
></ta-cell>
<ta-cell
label="左侧弹出"
isLink
@click="show({ title: '左侧弹出', placement: 'left' })"
></ta-cell>
<ta-cell
label="右侧弹出"
isLink
@click="show({ title: '右侧弹出', placement: 'right' })"
></ta-cell>
</ta-group>
<ta-group title="无标题">
<ta-cell label="底部弹出" isLink @click="show({ placement: 'bottom' })"></ta-cell>
<ta-cell label="右侧弹出" isLink @click="show({ placement: 'right' })"></ta-cell>
</ta-group>
<ta-group title="展示关闭按钮">
<ta-cell
label="有标题-底部"
isLink
@click="show({ title: '标题', placement: 'bottom', showClose: true })"
></ta-cell>
<ta-cell
label="有标题-右侧"
isLink
@click="show({ title: '标题', placement: 'right', showClose: true })"
></ta-cell>
<ta-cell
label="无标题"
isLink
@click="show({ placement: 'bottom', showClose: true })"
></ta-cell>
</ta-group>
<ta-group title="事件监听">
<ta-cell
label="visible-state-change"
isLink
@click="
show({
title: '标题',
placement: 'bottom',
showClose: true,
visibleEvent: true
})
"
></ta-cell>
<ta-cell
label="cancel"
isLink
@click="
show({
title: '标题',
placement: 'bottom',
showClose: true,
cancelEvent: true
})
"
></ta-cell>
</ta-group>
<ta-drawer
v-model:visible="drawerVisible"
:title="title"
:placement="placement"
:showClose="showClose"
@visibleStateChange="onVisibleStateChange"
@cancel="onCancel"
></ta-drawer>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue'
import {
type PlacementType,
showToast,
type PopupOnVisibleStateChange,
type PopupOnCancel
} from '@/index'
interface showArgs {
title?: string
placement?: PlacementType
showClose?: boolean
visibleEvent?: boolean
cancelEvent?: boolean
}
export default defineComponent({
name: 'ExpDrawer',
setup() {
const drawerVisible = ref(false)
const title = ref('')
const placement = ref<PlacementType>('top')
const showClose = ref(false)
const visibleEvent = ref(false)
const cancelEvent = ref(false)
function show(args: showArgs) {
title.value = args.title || ''
placement.value = args.placement || 'top'
showClose.value = args.showClose || false
visibleEvent.value = !!args.visibleEvent
cancelEvent.value = !!args.cancelEvent
drawerVisible.value = true
}
const onVisibleStateChange: PopupOnVisibleStateChange = ({ state }) => {
if (visibleEvent.value) {
showToast(`${state} 事件触发`)
console.log('visible-state-change', state)
}
}
const onCancel: PopupOnCancel = res => {
if (cancelEvent.value) {
showToast('取消')
console.log('cancel', res)
}
}
return {
drawerVisible,
title,
placement,
showClose,
show,
onVisibleStateChange,
onCancel
}
}
})
</script>
Import
js
import { TaDrawer } from 'tantalum-ui-mobile'
具体的引入方式可以参考引入组件。
Import Type
组件导出的类型定义:
ts
import type { VisibleState, PopupOnVisibleStateChange, PopupOnCancel } from 'tantalum-ui-mobile'
Props
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
v-model:visible | boolean | false | 否 | 是否显示 |
title | string | 否 | 标题,设置标题后展示头部栏 | |
placement | PlacementType | 'bottom' | 否 | 从哪展开,可选值:'bottom', 'top', 'left', 'right' |
show-close | boolean | false | 否 | 是否显示关闭按钮,显示按钮后展示头部栏 |
Events
事件 | 描述 | 回调函数参数 | TypeScript 函数 |
---|---|---|---|
visible-state-change | 展示隐藏时触发 | payload: { state: VisibleState } | PopupOnVisibleStateChange |
cancel | 关闭按钮或者点击蒙层关闭时触发 | payload: { source: string } | PopupOnCancel |
VisibleState 值说明
值 | 说明 | 备注 |
---|---|---|
show | 展示时触发 | |
shown | 展示且动画结束后触发 | |
hide | 隐藏时触发 | 可能携带其他参数 cancel, maskClick, closeClick 等 |
hidden | 隐藏且动画结束后触发 | 可能携带其他参数 cancel, maskClick, closeClick 等 |
Slots
#default
vue
<ta-drawer title="菜单" placement="right">
内容
</ta-drawer>