Vue组件——弹框组件案例

页面效果
在这里插入图片描述
实现代码:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>组件-弹框</title>
		<style>
			* {
				margin: 0;
				padding: 0;
			}

			.dialog {
				position: fixed;
				top: 0;
				left: 0;
				width: 100%;
				height: 100%;
				background-color: rgba(0, 0, 0, 0.2);
			}

			.dialog_container {
				background-color: #fff;
				width: 300px;
				height: 150px;
				margin: 100px auto;
				border-radius: 5px;
				padding: 10px;
			}

			.dialog_title>h3 {
				font-weight: 500;
				float: left;
			}

			.dialog_title>span {
				float: right;
				cursor: pointer;
			}

			.dialog_content {
				margin-top: 30px;
			}

			.dialog_content>p {
				text-align: center;
				color: #666;
			}

			.dialog_btn {
				text-align: right;
				margin-top: 30px;
			}

			.dialog_btn>button {
				border: 1px solid #ccc;
				width: 80px;
				height: 30px;
				border-radius: 5px;
			}

			.dialog_btn>button:first-child {
				background-color: #FFFFFF;
				color: #666666;
			}

			.dialog_btn>button:last-child {
				background-color: rgb(64, 158, 255);
				color: #FFFFFF;
			}

			.clearFix::after {
				content: '.';
				height: 0;
				display: block;
				clear: both;
				visibility: hidden;
			}

			/* 过渡样式 */
		</style>
		<!-- 引入 Animate.css 样式 -->
		<link href="https://cdn.jsdelivr.net/npm/animate.css@3.5.1" rel="stylesheet" type="text/css">
	</head>
	<body>
		<div id="app">
			<button @click="del">删除</button>

			<m-dialog :show-dialog='showDialog' :msg='msg' @close-dialog='closeDialog'></m-dialog>

		</div>
		<template id="dialog">
			<div class="dialog" v-show="showDialog">
				<transition enter-active-class="animated slideInDown">
					<div class="dialog_container" v-show="showDialog">
						<div class="dialog_title clearFix">
							<h3>提示</h3>
							<span @click="closeDialog">×</span>
						</div>
						<div class="dialog_content">
							<p>{{msg}}</p>
						</div>
						<div class="dialog_btn">
							<button type="button" @click="closeDialog">取消</button>
							<button type="button">确定</button>
						</div>
					</div>
				</transition>
			</div>
		</template>
		<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
		<script>
			//注册全局组件
			Vue.component('m-dialog', {
				props: {
					showDialog: {
						type: Boolean,
						default: false
					},
					msg: String
				},
				template: '#dialog',
				methods: {
					closeDialog() {
						this.$emit('close-dialog')
					}
				}
			})
			const vm = new Vue({
				el: '#app',
				data: {
					showDialog: false,
					msg: '这是一段信息'
				},
				methods: {
					del() {
						this.showDialog = true;

					},
					closeDialog() {
						this.showDialog = false;
					}
				}
			});
		</script>
	</body>
</html>

欢迎大家阅读,本人见识有限,写的博客难免有错误或者疏忽的地方,还望各位指点,在此表示感激不尽。文章持续更新中…

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

沐小侠

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

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

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

打赏作者

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

抵扣说明:

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

余额充值