uni-app底部弹出弹框,封装组件

组件内容

<template>
//@touchmove.prevent不让遮罩层后的页面滚动
//@tap.self只触发自己,或者给mask的子级.content加@tap.stop阻止事件默认行为
	<view @touchmove.prevent :class="sc" class="tankuang width-100 height-100 position-fixed p-left-0 p-top-0">
		<view class="mask width-100 height-100"  @tap.self="$emit('maskTap')">
			<view class="content width-100 position-absolute p-left-0 bj-white p-30" >
				<slot></slot>
				<!-- 按钮 -->
				<!--  @tap="$emit('bottomTap')" class="bottomBtn width-100 bj-primary-co$emit('bottomTap')自定义事件 -->
			<view @tap="$emit('bottomTap')" class="bottomBtn width-100 bj-primary-color text-center text-white position-fixed p-bottom-0 p-left-0">{{title}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props:{
			title:String,//按钮内容
			sc:String //控制calss类名
		},
		data() {
			return {
			};
		},
		methods:{
			
		}
	}
</script>

<style>
	/* 底部弹框 */
	.mask {
		background-color: rgba(0, 0, 0, 0.5);
	}

	.content {
		height: 1037upx;
		border-radius: 20upx 20upx 0 0;
		box-sizing: border-box;
		bottom: 0;
	}

	.none {
		display: none;
	}

	@keyframes contentHide {
		from {
			transform: translateY(0%);
		}

		to {
			transform: translateY(100%);
		}
	}

	@keyframes maskHide {
		from {
			opacity: 1;
		}

		to {
			opacity: 0;
		}
	}

	.hide .mask {
		animation: maskHide 0.2s linear both;
	}

	.hide .mask .content {
		animation: contentHide 0.2s linear both;
	}

	@keyframes contentShow {
		from {
			transform: translateY(100%);
		}

		to {
			transform: translateY(0%);
		}
	}

	@keyframes maskShow {
		from {
			opacity: 0;
		}

		to {
			opacity: 1;
		}
	}

	.show {
		display: block;
	}

	.show .mask {
		animation: maskShow 0.2s linear both;
	}

	.show .mask .content {
		animation: contentShow 0.2s linear both;
	}
	
	/* 底部按钮 */
	.bottomBtn {
		height: 100upx;
		line-height: 100upx;
		font-size: 26upx;
	}
</style>

页面

//点击这三个按钮
<view class="display-flex" @tap="listTap('car')"></view>
<view class="display-flex" @tap="listTap('address')"></view>
<view class="sevenBox display-flex" @tap="listTap('service')"></view>

<!-- 底部弹框1 -->
//popup组件名字,全局注册
		<popup title="加入购物车" :sc="fuClassName.car" @maskTap="maskTap('car')" @bottomTap="carTap">
			购物车
		</popup>
		
		<popup title="选择新的地址" :sc="fuClassName.address"  @maskTap="maskTap('address')" @bottomTap="addressTap">
			地址
		</popup>
		
		<popup title="确定" :sc="fuClassName.service"  @maskTap="maskTap('service')" @bottomTap="serviceTap">
			服务
		</popup>


//数据区
		data(){
			returm{
				fuClassName:{
					car:"none",
					address:"none",
					service:"none",
				},
			}
		},

		//方法区
		methods: {
			/* 点击出现 */
			listTap(key){
				this.fuClassName[key]='show'
			},
			/*点击底部弹框遮罩层 弹框消失  */
			maskTap(key) {
				this.fuClassName[key] = "hide";
				setTimeout(() => {
					this.fuClassName[key] = "none";
				}, 200)
			},
			/* 点击弹框里的按钮 */
			carTap(){
				this.maskTap('car')
				console.log("1")
			},
			addressTap(){
				this.maskTap('address')
				console.log("2")
			},
			serviceTap(){
				this.maskTap('service')
				console.log("3")
			}
			
	
			
			
		}









  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

裴嘉靖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值