Skip to content

t-popup

Popup 弹出层

组件介绍

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

平台兼容

HarmonyH5AndroidiOS小程序UTS

基础用法

vue
<template>
  <view class="popup-demo">
    <t-button type="primary" @click="showPopup = true">显示弹窗</t-button>
    
    <t-popup 
      v-model="showPopup"
      title="弹窗标题"
      direction="center"
      :maskClose="true"
      @confirm="handleConfirm"
      @cancel="handleCancel"
    >
      <view class="popup-content">
        <text>这是弹窗内容</text>
      </view>
    </t-popup>
  </view>
</template>

<script setup>
const showPopup = ref(false);

function handleConfirm() {
  console.log('点击确认');
  showPopup.value = false;
}

function handleCancel() {
  console.log('点击取消');
  showPopup.value = false;
}
</script>

<style scoped>
.popup-demo {
  padding: 40rpx;
}
.popup-content {
  padding: 40rpx;
  min-height: 200rpx;
}
</style>

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""标题-

Events

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

Slots

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

Direction 说明

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