Skip to content
On this page

组件库文档 tmui.design

抽屉 Drawer

弹出层容器,用于展示弹窗、信息提示等内容。


🌶️ 抽屉 Drawer 示例

查看模拟效果
示例模板
vue
<template>
	<tm-app>
		<tm-sheet>
			<tm-text :font-size="24" _class="text-weight-b" label="下面是基础演示属性,更多玩法请前往文档。"></tm-text>
			<tm-divider></tm-divider>
			<view class="flex flex-row flex-wrap">
				<tm-button
					:margin="[12, 12]"
					@click="changPos('bottom')"
					color="white"
					:width="120"
					:height="56"
					:font-size="24"
					label="底部"
				></tm-button>
				<tm-button :margin="[12, 12]" @click="changPos('top')" color="red" :width="120" :height="56" :font-size="24" label="顶部"></tm-button>
				<tm-button
					:margin="[12, 12]"
					@click="changPos('left')"
					color="orange"
					:width="120"
					:height="56"
					:font-size="24"
					label="左边"
				></tm-button>
				<tm-button
					:margin="[12, 12]"
					@click="changPos('right')"
					color="pink"
					:width="120"
					:height="56"
					:font-size="24"
					label="右边"
				></tm-button>
				<tm-button
					:margin="[12, 12]"
					@click="changPos('center')"
					color="green"
					:width="120"
					:height="56"
					:font-size="24"
					label="居中"
				></tm-button>
				<tm-drawer :beforeOk="beforeOk">
					<template v-slot:trigger>
						<tm-button
							block
							:margin="[12, 12]"
							:padding="[24, 0]"
							color="cyan"
							:height="56"
							:font-size="24"
							label="通过插槽触发弹层"
						></tm-button>
					</template>
				</tm-drawer>
			</view>
		</tm-sheet>

		<tm-drawer ref="calendarView" :placement="pos" v-model:show="showWin">
			<tm-button
				:margin="[12, 12]"
				@click="showWin2 = true"
				color="green"
				:width="160"
				:height="56"
				:font-size="24"
				label="内弹出盖内部"
			></tm-button>
			<tm-button
				:margin="[12, 12]"
				@click="showWin3 = true"
				color="green"
				:width="160"
				:height="56"
				:font-size="24"
				label="内弹出盖全屏"
			></tm-button>
			<tm-drawer inContent :width="300" :height="300" ref="calendarView" :placement="pos" v-model:show="showWin2"> </tm-drawer>
			<tm-drawer :width="300" :height="300" ref="calendarView" :placement="pos" v-model:show="showWin3"> </tm-drawer>
			<!-- inContent -->
			<!-- <tm-picker :height="500" inContent v-model:show="showWin2" :columns="citydate"></tm-picker> -->
		</tm-drawer>
	</tm-app>
</template>
<script lang="ts" setup>
import { ref, getCurrentInstance, nextTick } from 'vue'
import { onShow, onLoad } from '@dcloudio/uni-app'
import tmApp from '@/tmui/components/tm-app/tm-app.vue'
import tmSheet from '@/tmui/components/tm-sheet/tm-sheet.vue'
import tmText from '@/tmui/components/tm-text/tm-text.vue'
import tmButton from '@/tmui/components/tm-button/tm-button.vue'
import tmDivider from '@/tmui/components/tm-divider/tm-divider.vue'
import tmDrawer from '@/tmui/components/tm-drawer/tm-drawer.vue'
import tmCalendarView from '@/tmui/components/tm-calendar-view/tm-calendar-view.vue'
const calendarView = ref<InstanceType<typeof tmCalendarView> | null>(null)
const citydate = ref([
	{ text: '苹果', id: 0 },
	{ text: '香蕉', id: 1 },
	{ text: '其它水果', id: 2 },
	{ text: '越南水果', id: 4 }
])
const showWin = ref(false)
const showWin2 = ref(false)
const showWin3 = ref(false)
const pos = ref('bottom')
function changPos(params: string) {
	pos.value = params
	showWin.value = true
}

function beforeOk() {
	return new Promise((res) => {
		setTimeout(() => {
			res(true)
		}, 2000)
	})
}
</script>

🌶️ 兼容性

APP-VUEAPP-NVUE小程序WEB/H5VUE3/TS
✔️✔️✔️✔️✔️

🌱 参数

本组件含有公共属性 公共属性

参数名类型默认值描述
maskBooleantrue是否显示遮罩
placementStringtop抽屉放置的位置 可选:top,left,right,bottom,center
showBooleanfalse是否显示双向绑定可使用v-model:show
widthNumber500
heightNumber600
footHeightNumber0抽屉底部高度,可以固定底部的内容不受滚动影响
roundNumber, String12圆角像素
durationNumber300弹出动画的时间(毫秒)
overlayClickBooleantrue是否允许点击遮罩关闭
transprentBooleanfalse是否透明效果
closeableBooleanfalse是否显示关闭按钮(如果显示,标题栏被替换为左标题右关闭按钮)
colorStringwhite主题颜色
titleString''标题
okTextString完成确认按钮文字
okColorStringprimary确认按钮颜色
okLoadingStringprimarytrue时,确认按钮将出现加载状态
cancelTextString取消取消按钮文字
hideCancelBooleanfalse隐藏取消按钮
hideHeaderBooleanfalse隐藏工具栏,标题,取消,确认
disabledBooleanfalse禁止操作状态
zIndexv3.0.75+Number, String401弹层的层级
unitv3.0.75+Stringrpx高度单位,仅支持px,rpx
disabbleScrollBooleanfalse是否禁用内容滚动(内容较少时可以禁用滚动条的出现)
inContentBooleanfalse是否允许嵌套弹层,开启后嵌套弹层只会在父组件内部弹层,不会全屏弹层。
teleportBooleantrue(仅H5支持禁用)是否使用teleport
beforeCanceFunction,nullnull取消前执行,可以返回promise,如果是fase阻止关闭
beforeOkFunction,nullnull确认前执行,可以返回promise,如果是fase阻止关闭
beforeOpenFunction,nullnull打开前执行

🌹 事件

事件名参数返回数据描述
click
open显示抽屉
close关闭抽屉
ok确认按钮
cancel取消按钮
update:showshowBoolean显示状态(更新v-model:show值)

🌽 slot插槽

默认default,内容插槽 title v3.0.77+,标题插槽 trigger可触发弹层的插槽占位内容,比如在里面布局按钮,输入框,点击这块内容可以直接显示弹层。 foot,固定在弹层尾部内容。当drawer内容滚动时,这部分内容始终在尾部。属性footHeight必须大于0才会开启。

🥗 ref方法

方法名参数返回值描述
open显示
close隐藏

💏 文档贡献

此页文档由Kyour贡献,如果对该框架感兴趣的可以参与我们一同进步!