使用vue自定义简单的消息提示框
<style scoped>
/** 弹窗动画*/
a {
text-decoration: none
} .drop-enter-active {
/* 动画进入过程:0.5s */
transition: all 0.5s ease;
} .drop-leave-active {
/* 动画离开过程:0.5s */
transition: all 0.3s ease;
} .drop-enter {
/* 动画之前的位置 */
transform: translateY(-500px);
} .drop-leave-active {
/* 动画之后的位置 */
transform: translateY(-500px);
} /* 盒子显示 */ .message-dialog-display {
display: flex;
justify-content: center;
} /* 文本显示 */ .message-dialog-text {
text-align: center;
} /* 内容样式 */ .message-dialog-align {
align-content: center;
align-items: center;
} /* 最外层 设置position定位 */ .message-dialog {
position: relative;
font-size: 1rem;
} /* 遮罩 设置背景层,z-index值要足够大确保能覆盖,高度 宽度设置满 做到全屏遮罩 */ .message-dialog-cover {
position: fixed;
z-index: 200;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
} /* 内容层 z-index要比遮罩大,否则会被遮盖 */ .message-dialog-content {
position: fixed;
top: 35%;
flex-direction: column;
z-index: 300;
/* left: 2rem; */
width: 99%
} .message-dialog-header {
/* 头部title的背景 居中圆角等属性。
没有图片就把background-image注释掉 */
/* background-image: url("../../static/gulpMin/image/dialog/dialog_head.png"); */
width: 86%;
height: 43px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
background: #fbfbfb;
border-bottom: 0.01rem solid #fbfbfb
} .message-dialog-main {
/* 主体内容样式设置 */
background: #ffffff;
width: 86%;
padding: 1rem 0 1rem 0;
} .message-dialog-footer {
width: 86%;
height: 40px;
} .message-dialog-btn {
width: 100%;
height: 100%;
background: #fbfbfb;
position: relative;
display: flex;
align-content: center;
align-items: center;
justify-content: center;
line-height: 40px;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
border-top: 0.01rem solid #fbfbfb
} .message-dialog-sure a {
display: inline-block;
cursor: pointer;
background: #d6d6d6;
width: 4rem;
text-align: center;
height: 2rem;
line-height: 2rem;
border-radius: 0.2rem;
margin: 0 1rem;
} .message-dialog-close {
width: 100%;
display: flex;
justify-content: center;
align-content: center;
align-items: center;
text-align: center;
} .message-dialog-close a {
display: inline-block;
width: 100%;
height: 100%;
} .message-dialog-close a:hover {
color: aqua
}
</style>
@* <message-dialog :options.sync="options" v-on:close="close" :show.sync="showMessage" v-on:confirm="confirm" v-on:cancel="cancel"></message-dialog> *@
<template id="message_dialog">
<div class="message-dialog">
<div class="message-dialog-cover" v-if="myShow"></div>
<transition name="drop">
<div class="message-dialog-content message-dialog-display message-dialog-align"
v-bind:style="{width:myOptions.width+'%',left:myOptions.leftWidth+'%',top:myOptions.topDistance+'%'}"
v-if="myShow">
<div class="message-dialog-header message-dialog-text message-dialog-display message-dialog-align" v-if="myOptions.title">
<div>{{myOptions.title}}</div>
</div>
<div class="message-dialog-main message-dialog-text message-dialog-display message-dialog-align" v-bind:style="setStyle">
<div v-html="myOptions.content"></div>
</div>
<div class="message-dialog-footer" v-if="!myOptions.autoClose">
<div class="message-dialog-btn">
<div class="message-dialog-sure" v-if="myOptions.confirm">
<a v-on:click.stop="confirmed">确定</a>
<a v-on:click.stop="cancel">取消</a>
</div>
<div class="message-dialog-close" v-else>
<a v-on:click.stop="close">关闭</a>
</div>
</div>
</div>
</div>
</transition>
</div>
</template>
<template id="message-modal">
<div>
<message-dialog :options.sync="options" v-on:close="close" :show.sync="showMessage" v-on:confirm="confirm"
v-on:cancel="cancel"></message-dialog>
</div>
</template>
<script type="text/javascript">
Vue.component("message-dialog", {
template: '#message_dialog',
props: {
'options': {
type: Object,
default: () => {
return {};
}
},
'show': {
type: Boolean,
default: false
}
},
data() {
return {
timers: [],
myOptions: this.options,
myShow: this.show
};
},
methods: {
confirmed(e) {
this.$emit('confirm',e);
},
cancel() {
this.$emit('cancel');
},
close() {
this.$emit('close');
},
autoClose() {
if (this.myOptions.autoClose) {
const t = setTimeout(() => {
this.close();
}, this.myOptions.showTime || 3000);
this.timers.push(t);
}
} },
computed: {
setStyle() {
if (this.myOptions.autoClose && this.myOptions.title) {
return {
borderBottomLeftRadius: 10 + 'px',
borderBottomRightRadius: 10 + 'px',
};
} else {
if (!this.myOptions.title) {
return {
borderTopLeftRadius: 10 + 'px',
borderTopRightRadius: 10 + 'px',
};
}
}
}
},
watch: {
options() {
this.myOptions = this.options;
this.timers.forEach(timer => {
window.clearTimeout(timer);
});
this.timers = [];
this.autoClose();
},
show(value) {
this.myShow = value;
}
},
mounted() { },
}); var messageDialog = new Vue({
el: '#message',
template: "#message-modal",
data: {
options: {},
showMessage: false,
func: ""
},
methods: {
show: function (msg, title, issure, autoClose, showTime) {
if (!msg) {
return this;
}
this.options = {
content: msg,
title: title,
autoClose: autoClose,
showTime: showTime || 3000,
confirm: issure
};
this.showMessage = true;
return this;
},
showMsg: function (msg, autoClose, showTime) {
return this.show(msg, null, false, autoClose, showTime);
},
showHeaderMsg: function (title, msg, autoClose, showTime) {
return this.show(msg, title, false, autoClose, showTime);
},
showConfirm: function (title, msg, func) {
this.func = func;
return this.show(msg, title, true);
},
close: function () {
this.showMessage = false;
},
confirm: function (envent) {
if (this.func && this.func instanceof Function) {
this.func(envent, this);
}
this.showMessage = false;
},
cancel: function () {
this.showMessage = false;
}
}
});
</script>
使用vue自定义简单的消息提示框的更多相关文章
- Android:Toast简单消息提示框
Toast是简单的消息提示框,一定时间后自动消失,没有焦点. 1.简单文本提示的方法: Toast.makeText(this, "默认的toast", Toast.LENGTH_ ...
- 自定义iOS 中推送消息 提示框
看到标题你可能会觉得奇怪 推送消息提示框不是系统自己弹出来的吗? 为什么还要自己自定义呢? 因为项目需求是这样的:最近需要做 远程推送通知 和一个客服系统 包括店铺客服和官方客服两个模块 如果有新的消 ...
- Android开发 ---构建对话框Builder对象,消息提示框、列表对话框、单选提示框、多选提示框、日期/时间对话框、进度条对话框、自定义对话框、投影
效果图: 1.activity_main.xml 描述: a.定义了一个消息提示框按钮 点击按钮弹出消息 b.定义了一个选择城市的输入框 点击按钮选择城市 c.定义了一个单选提示框按钮 点击按钮选择某 ...
- UWP中的消息提示框(一)
不管什么平台,应用内难免会出现一些消息提示框,下面就来聊聊我在UWP里用到的消息提示框. 弹窗也可按是否需要用户操作促发一些逻辑进行分为两大类. 不需要用户干涉的一类: MessageDialog:操 ...
- UWP中的消息提示框(二)
在UWP中的消息提示框(一)中介绍了一些常见的需要用户主动去干涉的一些消息提示框,接下来打算聊聊不需要用户主动去干涉的一些消息提示框.效果就是像双击退出的那种提示框. 先说说比较简单的吧,通过系统To ...
- Android消息提示框Toast
Android消息提示框Toast Toast是Android中一种简易的消息提示框.和Dialog不一样的是,Toast是没有焦点的,toast提示框不能被用户点击,而且Toast显示的时间有限,t ...
- PowerShe 消息提示框测试
1. 使用powerShell 弹出一个简单的消息框,代码如下,创建test.ps1脚本文件. $ConfirmPreference = 'None' $ws = New-Object -ComObj ...
- wpf实现仿qq消息提示框
原文:wpf实现仿qq消息提示框 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/huangli321456/article/details/5052 ...
- 微信小程序API交互反馈,wx.showToast显示消息提示框
导读:wx.showToast(OBJECT) 显示消息提示框. OBJECT参数说明: 参数 类型 必填 说明 最低版本 title String 是 提示的内容 icon String 否 图标, ...
随机推荐
- dockerfile 介绍
Docker简介 Docker项目提供了构建在Linux内核功能之上,协同在一起的的高级工具.其目标是帮助开发和运维人员更容易地跨系统跨主机交付应用程序和他们的依赖.Docker通过Docker容器, ...
- SSH框架整合,css、js会被过滤器过滤掉
如果是默认状态 <!--struts2过滤器--> <filter> <filter-name>struts2</filter-name> <fi ...
- java基础 (一)之HashMap
HashMap的存储结构是由数组和链表共同完成.Entry<K,V>[] ,Entry是单向链表. 1 HashMap数据结构 HashMap的底层主要是基于数组和链表来实现的,它之所以有 ...
- week7 ls
week7 ls 实现ls: 实现ls -l:
- 文件下载 路径中有中文 报错 提示 文件找不到 java.io.FileNotFoundException: http://192.168.1.141:8096/resources/card/comcard/????????/????????.png
此问题主要是中文编码格式不对导致的,将路径中的中文部分设置下编码就可以啦 例如: String url = "http://192.168.1.141:8096/resources/car ...
- 机器学习 之KNN近邻法
目录 1.KNN近邻法 1.KNN近邻法 KNN模型由三个基本要素决定: 距离度量:其中欧式距离一般误差最小,\(x_{i} 和 x_{j}\)为两个样本点:\[L_{2}(x_{i}, x_{j}) ...
- 『Python』源码解析_从ctype模块理解对象
1.对象的引用计数 从c代码分析可知,python所有对象的内存有着同样的起始结构:引用计数+类型信息,实际上这些信息在python本体重也是可以透过包来一窥一二的, from ctypes impo ...
- hello2源代码解析
String username = request.getParameter("username");/**以 String 形式返回请求参数"username" ...
- PHP 第三方支付
以前事情比较繁忙,压根都没有时间去整理最近的工作. 最近稍微轻松点,就把自己在公司处理的支付业务拿出来,留个纪念,顺道回顾下以前自己支付的知识. 俗话说实践是检验整理的唯一标准,东西做的是否能用,只能 ...
- Problem E: 平面上的点——Point类 (V)
Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定.现在我们封装一个“Point类”来实现平面上的点的操作. 根据“append.cc”,完成Point类的构造方 ...