Skip to content
# t-popup

Popup 弹出层

t-popup 组件介绍 ​

功能丰富的弹出层解决方案,支持自定义显示状态、过渡效果、持续时间、弹出方向以及灵活的样式控制。

t-popup 平台兼容 ​

HarmonyH5AndroidiOS小程序UTS
✅✅✅✅✅✅

t-popup 基础用法 ​

基础用法参考 demo/popup/popup.uvue,支持五种弹出方向与动画开关配置。

vue
<template>
	<view>
		<tui-theme-switch></tui-theme-switch>
		<t-card class="mlrt-15"
				title="Popup 弹出层(停止维护请使用官方page-container)"
				sub-title="功能丰富的弹出层解决方案,支持自定义显示状态、过渡效果、持续时间、弹出方向以及灵活的样式控制"></t-card>
		<introduction title='方向'>
			<t-button class='mb-15'
					  type="primary"
					  @click="popupleftShow">左侧弹出(关闭动画效果)</t-button>
			<t-button class='mb-15'
					  type="primary"
					  @click="popuprighthow">右侧弹出</t-button>
			<t-button class='mb-15'
					  type="primary"
					  @click="popuptopShow">顶部弹出</t-button>
			<t-button class='mb-15'
					  type="primary"
					  @click="popupbottomShow">底部弹出</t-button>
			<t-button class='mb-15'
					  type="primary"
					  @click="popupcenterShow">中间弹出</t-button>
		</introduction>
		<t-popup direction="left"
				 ref='popupleft'
				 :show-footer="true"
				 :transition="false"
				 type="error"
				 size="mini">
			<view class="w-275 h-100% fc">
				<t-button type="error"
						  @click="popupleftShow">点我关闭(关闭动画)</t-button>
			</view>
		</t-popup>
		<t-popup direction="right"
				 ref='popupright'
				 :show-footer="true"
				 :mask-close="false">
			<view class="w-275 h-100% fc ">
				<t-button type="error"
						  @click="popuprighthow">点我关闭(禁用遮罩层关闭)</t-button>
			</view>
		</t-popup>
		<t-popup direction="top"
				 ref='popuptop'
				 :show-footer="true">
			<view class='h-300 fc r-0px,0px,8,8'>
				<t-button type="error"
						  @click="popuptopShow">点我关闭</t-button>
			</view>
		</t-popup>
		<t-popup direction="bottom"
				 ref='popupbottom'
				 :show-footer="true"
				 :closeable="true">
			<view class="h-400 fc">
				<t-button type="error"
						  @click="popupbottomShow">点我关闭</t-button>
			</view>
		</t-popup>
		<t-popup direction="center"
				 ref='popupcenter'
				 :show-footer="true"
				 :closeable="true">
			<view class="h-200 fc w-250">
			</view>
		</t-popup>
		<view class="h-2500"></view>
	</view>
</template>

<script setup>
	const popupleft = ref<ComponentPublicInstance | null>(null)
	const popupright = ref<ComponentPublicInstance | null>(null)
	const popuptop = ref<ComponentPublicInstance | null>(null)
	const popupbottom = ref<ComponentPublicInstance | null>(null)
	const popupcenter = ref<ComponentPublicInstance | null>(null)
	function popupleftShow() {
		popupleft.value?.$callMethod('show')
	}
	function popuprighthow() {
		popupright.value?.$callMethod('show')
	}
	function popuptopShow() {
		popuptop.value?.$callMethod('show')
	}
	function popupbottomShow() {
		popupbottom.value?.$callMethod('show')
	}
	function popupcenterShow() {
		popupcenter.value?.$callMethod('show')
	}
</script>

t-popup Props ​

属性名类型默认值说明可选值
sizeString"medium"组件尺寸large, medium, small, mini
typeString""组件类型info, primary, error, warning, success
disabledBooleanfalse组件是否禁用true, false
stopBooleanfalse是否阻止事件冒泡true, false
hoverBooleanfalse是否有点击效果true, false
pathString""点击组件后跳转的页面路径-
effectString"normal"组件显示主题normal, dark, light, plain
cancelTextString"取消"取消按钮的文本-
confirmTextString"确认"确认按钮的文本-
transitionBooleantrue是否开启过渡动画效果true, false
maskCloseBooleantrue点击遮罩层是否关闭窗口true, false
durationNumber200过渡动画的时间-
directionString"left"弹出层的进入页面的方向left, right, top, bottom, center
contentClassString""内容区容器样式-
closeableBooleanfalse是否显示关闭按钮true, false
closeableClassString""关闭按钮样式-
showFooterBooleantrue是否显示底部按钮true, false
footerClassString""底部按钮样式-
headerClassString""标题栏容器样式-
titleClassString""标题样式-
titleString""标题-

t-popup Events ​

事件名说明回调参数
confirm点击确认按钮时触发-
cancel点击取消按钮时触发-
close点击关闭按钮时触发-
click点击时触发-
transitionend动画结束时触发-
initFinished组件初始化完成触发组件的节点信息
touchstart触摸开始时触发触摸事件对象
touchend触摸结束时触发触摸事件对象
touchmove触摸移动时触发触摸事件对象
touchcancel触摸取消时触发触摸事件对象

t-popup Slots ​

插槽名说明
default内容插槽,用于放置弹窗的主体内容
header标题栏插槽,用于自定义标题栏内容
footer底部按钮插槽,用于自定义底部按钮

Direction 说明 ​

方向值说明动画效果
left从左侧弹出从左侧滑入
right从右侧弹出从右侧滑入
top从顶部弹出从顶部滑入
bottom从底部弹出从底部滑入
center从中心弹出从中心缩放