t-popup
Popup 弹出层
组件介绍
功能丰富的弹出层解决方案,支持自定义显示状态、过渡效果、持续时间、弹出方向以及灵活的样式控制。
平台兼容
| Harmony | H5 | Android | iOS | 小程序 | 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
| 属性名 | 类型 | 默认值 | 说明 | 可选值 |
|---|---|---|---|---|
| size | String | "medium" | 组件尺寸 | large, medium, small, mini |
| type | String | "" | 组件类型 | info, primary, error, warning, success |
| disabled | Boolean | false | 组件是否禁用 | true, false |
| stop | Boolean | false | 是否阻止事件冒泡 | true, false |
| hover | Boolean | false | 是否有点击效果 | true, false |
| path | String | "" | 点击组件后跳转的页面路径 | - |
| effect | String | "normal" | 组件显示主题 | normal, dark, light, plain |
| cancelText | String | "取消" | 取消按钮的文本 | - |
| confirmText | String | "确认" | 确认按钮的文本 | - |
| transition | Boolean | true | 是否开启过渡动画效果 | true, false |
| maskClose | Boolean | true | 点击遮罩层是否关闭窗口 | true, false |
| duration | Number | 200 | 过渡动画的时间 | - |
| direction | String | "left" | 弹出层的进入页面的方向 | left, right, top, bottom, center |
| contentClass | String | "" | 内容区容器样式 | - |
| closeable | Boolean | false | 是否显示关闭按钮 | true, false |
| closeableClass | String | "" | 关闭按钮样式 | - |
| showFooter | Boolean | true | 是否显示底部按钮 | true, false |
| footerClass | String | "" | 底部按钮样式 | - |
| headerClass | String | "" | 标题栏容器样式 | - |
| titleClass | String | "" | 标题样式 | - |
| title | String | "" | 标题 | - |
Events
| 事件名 | 说明 | 回调参数 |
|---|---|---|
| confirm | 点击确认按钮时触发 | - |
| cancel | 点击取消按钮时触发 | - |
| close | 点击关闭按钮时触发 | - |
| click | 点击时触发 | - |
| transitionend | 动画结束时触发 | - |
| initFinished | 组件初始化完成触发 | 组件的节点信息 |
| touchstart | 触摸开始时触发 | 触摸事件对象 |
| touchend | 触摸结束时触发 | 触摸事件对象 |
| touchmove | 触摸移动时触发 | 触摸事件对象 |
| touchcancel | 触摸取消时触发 | 触摸事件对象 |
Slots
| 插槽名 | 说明 |
|---|---|
| default | 内容插槽,用于放置弹窗的主体内容 |
| header | 标题栏插槽,用于自定义标题栏内容 |
| footer | 底部按钮插槽,用于自定义底部按钮 |
Direction 说明
| 方向值 | 说明 | 动画效果 |
|---|---|---|
| left | 从左侧弹出 | 从左侧滑入 |
| right | 从右侧弹出 | 从右侧滑入 |
| top | 从顶部弹出 | 从顶部滑入 |
| bottom | 从底部弹出 | 从底部滑入 |
| center | 从中心弹出 | 从中心缩放 |