UNI-APP弹窗

组件代码

html 复制代码
<template>
	<view>
		<!-- 蒙版 -->
		<view class="mask" @click="close()" v-show="tanchuang"></view>
		<!-- 弹窗 -->
		<view class="pop" :style="{height:height*0.8 + 'px',top:tanchuang?height*0.2 + 'px':height + 'px'}">
			<!-- 头部 -->
			<view class="" style="width: 100%;" @click="close()">
				<view class="huaxian"></view>
			</view>
			<!-- 内容 -->
			<scroll-view scroll-y="true" :style="{maxHeight: `${scrollHeight}px`}">
				<slot></slot>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	let systemInfo = uni.getSystemInfoSync();
	export default {
		name: "pop-up",
		props: {
			tanchuang: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				height: systemInfo.screenHeight,
				scrollHeight: systemInfo.screenHeight * 0.8 - uni.upx2px(100),

			};
		},
		methods: {
			close() {
				this.$emit('close');
			},
		}
	}
</script>

<style lang="scss">
	/* 划线 */
	.huaxian {
		height: 10rpx;
		width: 200rpx;
		background: #bbbbbb;
		border-radius: 100rpx;
		margin: auto;
		margin-top: 30rpx;
		margin-bottom: 30rpx;
	}

	/* 蒙版 */
	.mask {
		z-index: 998;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background-color: rgba(0, 0, 0, 0.5);
	}

	/*  */

	.pop {
		position: fixed;
		// width: 750rpx;
		background-color: #fff;
		border-radius: 30rpx 30rpx 0 0;
		left: 0;
		right: 0;
		transition-property: top;
		transition-duration: 150ms;
		transition-timing-function: ease-in-out;
		z-index: 999;

		.title {
			padding: 30rpx 30rpx 0;
			align-items: center;
			justify-content: center;
			line-height: 40rpx;
		}

		&--close-btn {
			height: 40rpx;
			width: 40rpx;
			position: absolute;
			right: 30rpx;
			top: 30rpx;
		}
	}

	.border-bottom {
		width: 750rpx;
		border-bottom: 1rpx solid #e8e8e8;
		transform: scaleY(.5);
		margin-top: 30rpx;
	}
</style>

组件的使用

html 复制代码
<template>
	<view>

		<button @click="tanchuang = true">打开</button>
		<pop-up :tanchuang="tanchuang" @close="tanchuang = false">

			<view class="article-list">

				弹窗内容

			</view>

		</pop-up>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				tanchuang: false
			}
		},
		methods: {

		}
	}
</script>

<style>

</style>
相关推荐
流烟默8 小时前
vue和微信小程序处理markdown格式数据
前端·vue.js·微信小程序
乔冠宇13 小时前
微信小程序中将图片截图为正方形(自动居中)
微信小程序·小程序·typescript·uniapp
V+zmm1013416 小时前
在线办公小程序(springboot论文源码调试讲解)
vue.js·spring boot·微信小程序·小程序·毕业设计
V+zmm1013417 小时前
自驾游拼团小程序的设计与实现(ssm论文源码调试讲解)
java·数据库·微信小程序·小程序·毕业设计
黑马源码库miui520861 天前
挪车小程序挪车二维码php+uniapp
微信小程序·小程序·微信公众平台
盛夏绽放1 天前
微信小程序地图map全方位解析
微信小程序·小程序
初尘屿风1 天前
基于微信小程序的电影院订票选座系统的设计与实现,SSM+Vue+毕业论文+开题报告+任务书+指导搭建视频
vue.js·微信小程序·小程序
敲代码的鱼哇2 天前
设备唯一ID获取,支持安卓/iOS/鸿蒙Next(uni-device-id)UTS插件
android·ios·uniapp·harmonyos
韩召华2 天前
微信小程序(uni)+蓝牙连接+Xprint打印机实现打印功能
微信小程序·小程序·notepad++
愤怒的山羊2 天前
微信小程序消息推送解密
微信小程序·小程序