Popup 弹出层

弹出层容器,用于展示弹窗、信息提示等内容,支持多个方向弹出。

代码示例

				
<template>
	<zk-theme type="page" :padding="30" showBack navbarTitle=" popup 弹出层 ">
		<!-- 基础用法 -->
		<zk-theme type="card" :padding="30" :radius="16" margin="0 0 40rpx 0">
			<zk-text type="secondary" :size="28" weight="bold" margin="0 0 20rpx 0" text="基础用法" />
			<view class="demo-row">
				<zk-button text="展示弹出层" type="primary" @click="showBasic = true" />
			</view>
			<zk-popup :show="showBasic" @close="showBasic = false">
				<view class="popup-content">
					<zk-text class="popup-text" text="基础弹出层" />
				</view>
			</zk-popup>
		</zk-theme>

		<!-- 弹出位置 -->
		<zk-theme type="card" :padding="30" :radius="16" margin="0 0 40rpx 0">
			<zk-text type="secondary" :size="28" weight="bold" margin="0 0 20rpx 0" text="弹出位置" />
			<view class="demo-row">
				<view class="btn-wrap" v-for="item in positions" :key="item">
					<zk-button :text="`${item}方向弹出`" size="small" type="success" @click="showPosition(item)" />
				</view>
			</view>
			<zk-popup :show="show" :position="position" @close="show = false">
				<view class="popup-content">
					<zk-text class="popup-text" :text="`${position}弹出层`" />
				</view>
			</zk-popup>
		</zk-theme>

		<!-- 关闭图标 -->
		<zk-theme type="card" :padding="30" :radius="16" margin="0 0 40rpx 0">
			<zk-text type="secondary" :size="28" weight="bold" margin="0 0 20rpx 0" text="关闭图标" />
			<view class="demo-row">
				<zk-button text="展示关闭图标" type="success" @click="showClose = true" />
			</view>
			<zk-popup :show="showClose" closeable position="bottom" @close="showClose = false">
				<view class="popup-content">
					<zk-text class="popup-text" text="展示关闭图标" />
				</view>
			</zk-popup>
		</zk-theme>

		<!-- 圆角弹窗 -->
		<zk-theme type="card" :padding="30" :radius="16" margin="0 0 40rpx 0">
			<zk-text type="secondary" :size="28" weight="bold" margin="0 0 20rpx 0" text="圆角弹窗" />
			<view class="demo-row">
				<zk-button text="展示圆角弹窗" type="warning" @click="showRound = true" />
			</view>
			<zk-popup :show="showRound" round position="bottom" @close="showRound = false">
				<view class="popup-content">
					<zk-text class="popup-text" text="圆角弹窗" />
				</view>
			</zk-popup>
		</zk-theme>

		<!-- 无动画弹出层 -->
		<zk-theme type="card" :padding="30" :radius="16" margin="0 0 40rpx 0">
			<zk-text type="secondary" :size="28" weight="bold" margin="0 0 20rpx 0" text="无动画弹出层" />
			<view class="demo-row">
				<zk-button text="无动画弹出" type="danger" @click="showNoTransition = true" />
			</view>
			<zk-popup :show="showNoTransition" :transition="false" @close="showNoTransition = false">
				<view class="popup-content">
					<zk-text class="popup-text" text="无动画弹出层" />
				</view>
			</zk-popup>
		</zk-theme>
	</zk-theme>
</template>

<script>
	export default {
		data() {
			return {
				showBasic: false,
				show: false,
				position: 'center',
				positions: ['top', 'bottom', 'left', 'right'],
				showClose: false,
				showRound: false,
				showNoTransition: false
			}
		},

		methods: {
			showPosition(position) {
				this.position = position
				this.show = true
			}
		}
	}
</script>

<style>
	.demo-row {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		flex-wrap: wrap;
	}

	.btn-wrap {
		margin-right: 30rpx;
		margin-bottom: 30rpx;
	}

	.popup-content {
		padding: 30rpx;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		align-items: center;
		justify-content: center;
		height: 200rpx;
		width: 200rpx;
	}

	.popup-text {
		font-size: 28rpx;
		text-align: center;
	}

	/* #ifdef APP-NVUE */
	.demo-row {
		flex-direction: row;
		flex-wrap: wrap;
	}

	/* #endif */
</style>
			

API

Props 属性

参数 说明 类型 可选值 默认值 是否必填
show 是否显示弹出层 boolean true / false false
position 弹出位置 string center / top / right / bottom / left center
overlay 是否显示遮罩层 boolean true / false true
round 是否显示圆角 boolean true / false false
closeOnClickOverlay 是否在点击遮罩层后关闭 boolean true / false true
closeable 是否显示关闭图标 boolean true / false false
closeIconPosition 关闭图标位置 string top-left / top-right / bottom-left / bottom-right top-right
customStyle 自定义样式 object - {}
zIndex z-index 层级 number - 9999
backgroundColor 弹出层背景色 string - ''
overlayColor 遮罩层颜色 string - rgba(0, 0, 0, 0.7)

Events 事件

事件名 说明 回调参数
close 点击关闭按钮、遮罩层或按下 ESC 时触发 -

Slots 插槽

名称 说明
default 弹出层内容