vue自定义插件-弹框
<template>
<transition name="msgbox">
<div v-if="show" class="msgbox-container" :class="className">
<header>{{title}}</header>
<div class="content-body">
<div>弹出内容可以嵌入html标签</div>
</div>
<footer>
<a v-if="cancel" href="javascript:;" @click="cancelBtn" class="button">{{cancel}}</a>
<a href="javascript:;" @click="successBtn" class="button">{{confirm}}</a>
</footer>
</div>
</transition>
</template>
<script>
export default {
data () {
return {
show: false,
title: '提示',
content: '',
confirm: '确定',
cancel:'',
className:''
}
},
watch:{
show (val) {
if (val) {
if(!this.hasClass(document.body,"pop-mask")){
this.addClass(document.body,"pop-mask");
}
}else{
this.removeClass(document.body,"pop-mask");
}
}
},
beforeMount () {
//如果已经存在,则阻止出现第二次
let node = document.querySelector('.msgbox-container')
if (node && node.parentNode) {
node.parentNode.removeChild(node)
}
},
methods: {
successBtn () {
this.show = false;
},
cancelBtn () {
this.show = false;
},
addClass(obj, cls){
var obj_class = obj.className,
blank = (obj_class != '') ? ' ' : '';
var added = obj_class + blank + cls;
obj.className = added;
},
removeClass(obj, cls){
var obj_class = ' '+obj.className+' ';
obj_class = obj_class.replace(/(\s+)/gi, ' ');
var removed = obj_class.replace(' '+cls+' ', ' ');
removed = removed.replace(/(^\s+)|(\s+$)/g, '');
obj.className = removed;//替换原来的 class.
},
hasClass(obj, cls){
var obj_class = obj.className,
obj_class_lst = obj_class.split(/\s+/);
var x = 0;
for(x in obj_class_lst) {
if(obj_class_lst[x] == cls) {
return true;
}
}
return false;
}
}
}
</script>
<style lang="scss" scoped>
.msgbox-container{
position: fixed;
top:50%;
left:50%;
width: 90%;
background: #fff;
color: #555;
border-radius: 0.8rem;
transform:translate(-50%,-50%) scale(1, 1);
header{
margin:;
padding: 1.2rem 0;
text-align: center;
color: #333;
height: 2rem;
line-height: 2rem;
font-size: 1.7rem;
border-radius: 0.8rem 0.8rem 0 0;
background: #fff;
border-width:;
border-bottom: 1px solid #ccc;
}
.content-body{
font-size: 1.5rem;
margin: 2rem 1rem;
line-height:;
max-height: 20rem;
overflow-y: auto;
color: #666;
div{
padding: 0 1rem;
text-align: justify;
word-break: break-all;
}
}
footer {
width: 100%;
text-align: center;
display: block !important;
border-width:;
border-top: 1px solid #ccc;
overflow: hidden;
background: transparent;
border-radius: 0 0 0.8rem 0.8rem;
.button{
float: left;
padding: 1rem 0;
width: 50%;
color: #999;
box-sizing: border-box;
line-height: 3rem;
font-size: 1.7rem;
background: #f7f7f7;
border-right: 1px solid #D5D7D6;
text-decoration: none;
-webkit-tap-highlight-color: transparent;
}
.button:first-child:nth-last-child(1) {
width: 100%;
}
.button:first-child:nth-last-child(2) ~ .button {
width: 50%;
}
}
}
.msgbox-enter,.msgbox-leave-to{
-webkit-transform: translate(-50%,-50%) scale(0,0);
}
.msgbox-enter-active,.msgbox-leave-active{
-webkit-transition: all .3s;
transition: all .3s;
}
.msgbox-enter-to,.msgbox-leave{
-webkit-transform: translate(-50%,-50%) scale(1,1);
}
</style>
最后在 main.js 里面 配置
import emComponent from './components/custom/index'
Vue.use(emComponent)
具体使用方法
<template>
<div>
<label id="msgbox" @click.stop="showMsgbox">点击我显示msgbox</label>
</div>
</template>
<script>
<script>
export default {
name: 'test',
data(){
return { }
},
methods:{
showMsgbox(){
this.$msgbox({
title:'温馨提示',
cancel:'取消',
content:'这里是消息弹出内容',
confirm:'确定按钮',
className:'pop-custom'
}).then(()=>{
console.log("我点击了确定按钮")
}).catch((err)=>{
console.log("error");
})
}
}
}
</script>
源码地址https://github.com/zuobaiquan/vue/tree/master/vueExercise/vue-component/src/components/custom
vue自定义插件-弹框的更多相关文章
- vue 自定义动态弹框
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vue自定义插件封装,实现简易的elementUi的Message和MessageBox
vue自定义插件封装示例 1.实现message插件封装(类似简易版的elementUi的message) message组件 <template> <transition ...
- JavaScript实现自定义alert弹框
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAh0AAAFkCAYAAACEpYlzAAAfj0lEQVR4nO3dC5BddZ0n8F93pxOQCO
- CodePush自定义更新弹框及下载进度条
CodePush 热更新之自定义更新弹框及下载进度 先来几张弹框效果图 非强制更新场景 image 强制更新场景 image 更新包下载进度效果 image 核心代码 这里的热更新Modal框,是封装 ...
- vue移动端弹框组件,vue-layer-mobile
最近做一个移动端项目,弹框写的比较麻烦,查找资料,找到了这个组件,但是说明文档比较少,自己研究了下,把我碰到的错,和详细用法分享给大家!有疑问可以打开组件看一看,这个组件是仿layer-mobile的 ...
- 自定义alert弹框,title不显示域名
问题: 系统默认的alert弹框的title会默认显示网页域名 解决办法: (修改弹框样式) (function() { window.alert = function(name) { $(" ...
- WPF 如何自定义一个弹框
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 简述: 手工以原生Grid的方式,自定义了一个仿弹窗效果,优点可以自定义,缺点需要自己实现以及维护整个弹窗的效 ...
- Vue 自定义全局消息框组件
消息弹框组件,默认3秒后自动关闭,可设置info/success/warning/error类型 效果图: 文件目录: Message.vue <template> <transit ...
- 自定义alert弹框,title不显示域名(重写alert)
问题: 系统默认的alert弹框的title会默认显示网页域名 解决办法: (修改弹框样式) (function() { window.alert = function(name) { $(" ...
随机推荐
- 【Python3练习题 025】 一个数,判断它是不是回文数。即12321是回文数,个位与万位相同,十位与千位相同
[Python练习题 025] 一个5位数,判断它是不是回文数.即12321是回文数,个位与万位相同,十位与千位相同 x = input('请输入任意位数的数字:') if x == x[::-1]: ...
- [转帖]Windows批处理(cmd/bat)常用命令小结
Windows批处理(cmd/bat)常用命令小结 非常值得学习的文档 先放这里 有时间做实验, 转载自:“趣IT”微信公共号 前言 批处理文件(batch file)包含一系列 DOS命令,通常用于 ...
- [转帖]HPE的软件部分到底是谁的?
英国Micro Focus公司收购惠普旗下软件部门 http://www.gongkong.com/news/201710/369740.html 搞不清楚 现在ALM 到底是谁的资产了.. 据国外媒 ...
- 372.Definition of ListNode
单项列表只能把后一个node中的所有数据copy到当前node再delete后一node. /** * Definition of ListNode * class ListNode { * publ ...
- vue-cli 上传图片上传到OSS(阿里云)
https://help.aliyun.com/document_detail/32068.html?spm=5176.doc32069.6.304.Qc4SUs(看) https://help.al ...
- MySQL索引管理及执行计划
一.索引介绍 二.explain详解 三.建立索引的原则(规范)
- 简单易懂的softmax交叉熵损失函数求导
参考: https://blog.csdn.net/qian99/article/details/78046329
- python之路--内置函数03
一 . 正则表达式 匹配字符串 元字符 . 除了换行 \w 数字, 字母, 下划线 \d 数字 \s 空白符 \n \t \b 单词的边界 \W 非xxx \D \S [ ] 字符组 or的关系 [^ ...
- 在linux系统中实现各项监控的关键技术(2)--内核态与用户态进程之间的通信netlink
Netlink 是一种在内核与用户应用间进行双向数据传输的非常好的方式,用户态应用使用标准的 socket API 就可以使用 netlink 提供的强大功能,内核态需要使用专门的内核 API 来使用 ...
- java.util.concurrent.TimeoutException: Idle timeout expired: 300000/300000 ms
Request idle timed out at 123000 ms. That means there was no activity (read or write) for 123000 ms ...