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>
相关推荐
半生过往6 小时前
微信小程序文件下载与预览功能实现详解
微信小程序·小程序·notepad++·压缩包下载解压
源码_V_saaskw6 小时前
JAVA图文短视频交友+自营商城系统源码支持小程序+Android+IOS+H5
java·微信小程序·小程序·uni-app·音视频·交友
996幸存者10 小时前
uni-app区域选择、支持静态、动态数据
微信小程序·uni-app
ᥬ 小月亮12 小时前
Uniapp编写微信小程序,绘制动态圆环进度条
微信小程序·小程序·uni-app
The_era_achievs_hero19 小时前
UniappDay03
vue.js·微信小程序·uni-app
Python大数据分析2 天前
uniapp之微信小程序标题对其右上角按钮胶囊
微信小程序·小程序·uni-app
The_era_achievs_hero2 天前
uni-appDay02
javascript·vue.js·微信小程序·uni-app
黑马源码库miui520863 天前
JAVA图文短视频交友+自营商城系统源码支持小程序+Android+IOS+H5
java·微信小程序·小程序·uni-app·音视频·交友
郭邯4 天前
小程序视图层学习笔记
微信小程序
拾光拾趣录4 天前
小程序双线程架构:为什么需要两个线程才能跳舞?
前端·微信小程序