<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自定义简单的消息提示框的更多相关文章

  1. Android:Toast简单消息提示框

    Toast是简单的消息提示框,一定时间后自动消失,没有焦点. 1.简单文本提示的方法: Toast.makeText(this, "默认的toast", Toast.LENGTH_ ...

  2. 自定义iOS 中推送消息 提示框

    看到标题你可能会觉得奇怪 推送消息提示框不是系统自己弹出来的吗? 为什么还要自己自定义呢? 因为项目需求是这样的:最近需要做 远程推送通知 和一个客服系统 包括店铺客服和官方客服两个模块 如果有新的消 ...

  3. Android开发 ---构建对话框Builder对象,消息提示框、列表对话框、单选提示框、多选提示框、日期/时间对话框、进度条对话框、自定义对话框、投影

    效果图: 1.activity_main.xml 描述: a.定义了一个消息提示框按钮 点击按钮弹出消息 b.定义了一个选择城市的输入框 点击按钮选择城市 c.定义了一个单选提示框按钮 点击按钮选择某 ...

  4. UWP中的消息提示框(一)

    不管什么平台,应用内难免会出现一些消息提示框,下面就来聊聊我在UWP里用到的消息提示框. 弹窗也可按是否需要用户操作促发一些逻辑进行分为两大类. 不需要用户干涉的一类: MessageDialog:操 ...

  5. UWP中的消息提示框(二)

    在UWP中的消息提示框(一)中介绍了一些常见的需要用户主动去干涉的一些消息提示框,接下来打算聊聊不需要用户主动去干涉的一些消息提示框.效果就是像双击退出的那种提示框. 先说说比较简单的吧,通过系统To ...

  6. Android消息提示框Toast

    Android消息提示框Toast Toast是Android中一种简易的消息提示框.和Dialog不一样的是,Toast是没有焦点的,toast提示框不能被用户点击,而且Toast显示的时间有限,t ...

  7. PowerShe 消息提示框测试

    1. 使用powerShell 弹出一个简单的消息框,代码如下,创建test.ps1脚本文件. $ConfirmPreference = 'None' $ws = New-Object -ComObj ...

  8. wpf实现仿qq消息提示框

    原文:wpf实现仿qq消息提示框 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/huangli321456/article/details/5052 ...

  9. 微信小程序API交互反馈,wx.showToast显示消息提示框

    导读:wx.showToast(OBJECT) 显示消息提示框. OBJECT参数说明: 参数 类型 必填 说明 最低版本 title String 是 提示的内容 icon String 否 图标, ...

随机推荐

  1. 浅谈Cocos2d-js cc.director

    在cocos2d-x里面,游戏的任何时间,只有一个场景对象实例处于运行状态,该对象可以作为当前游戏内容的整体包对象. 环境设定 进入游戏之前,导演会设置游戏的运行环境: 设置游戏视图,包含视图的投射, ...

  2. LINQ解析

    Linq 是什么? Linq是Language Integrated Query的缩写,即“语言集成查询“的意思,Linq的提出就是为了提供一种跨各种数据源统一查询方式,主要包含四种组件:Linq t ...

  3. collection.Counter

    a=['A','B','C','A','D','E','W','A','B'] b=collections.Counter(a)  # 可以统计a中的各个元素出现的次数print(b)print(b[ ...

  4. synchronized同步方法《二》

    1.synchronized方法和锁对象 (1).验证线程锁的是对象 代码如下: 1.1创建一个MyObject类: package edu.ymm.about_thread4; public cla ...

  5. 【分布式搜索引擎】初识Elasticsearch

    一.Elasticsearch是什么? Elasticsearch是一个基于Apache Lucene(TM)的开源搜索引擎. Elasticsearch是一个实时分布式搜索和分析引擎.它让你以前所未 ...

  6. openLDAP安装时无法操作根节点数据,提示的是This base cannot be created with PLA.

    1.无法操作根节点数据,提示的是This base cannot be created with PLA. 解决办法 1)添加一个base.ldif文件,里面的dc和配置文件里的保持一致即可 dn: ...

  7. python自动化测试入门篇-jemter参数化

    一.Jmeter参数化 1.使用用户自定义变量 用户定义的变量,引用方式:${定义参数名称};例如定义一个变量IP,使用它的时候用 ${IP}. 添加一个 User Defined Variables ...

  8. jQuery 省份选择

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. 如何正确使用QThread

    如何正确使用QThread https://www.2cto.com/kf/201609/550462.html

  10. 各大型网站架构分析收集-原网址http://blog.csdn.net/lovingprince/article/details/3379710

    1. PlentyOfFish 网站架构学习http://www.dbanotes.net/arch/plentyoffish_arch.html 采取 Windows 技术路线的 Web 2.0 站 ...