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>
相关推荐
2501_9335090721 分钟前
无锡制造企税惠防错指南:知了问账帮守政策红利线
大数据·人工智能·微信小程序
汤姆yu3 小时前
基于微信小程序的智慧社区娱乐服务管理平台
微信小程序·娱乐
千寻技术帮6 小时前
50013_基于微信小程序的校园志愿者系统
mysql·微信小程序·springboot·文档·ppt
汤姆yu8 小时前
基于微信小程序的民宿预定系统
微信小程序·小程序·民宿预定
黑夜世界16 小时前
微信小程序map组件聚合簇样式自定义
微信小程序·小程序
qq_124987075319 小时前
基于微信小程序的茶叶茶具销售和管理系统(源码+论文+部署+安装)
微服务·微信小程序·小程序·毕业设计
CDwenhuohuo19 小时前
微信小程序里用 setData() 修改数据并打印输出 的几种写法
javascript·微信小程序·小程序
小明记账簿1 天前
微信小程序开发实战:图片转 Base64 全解析
微信小程序·小程序
汤姆yu1 天前
基于微信小程序的粤语文化传播系统
微信小程序·小程序
Q_Q5110082851 天前
python+uniapp基于微信小程序的垃圾分类信息系统
spring boot·python·微信小程序·django·flask·uni-app·node.js