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) { $(" ...
随机推荐
- CRM系统(第三部分)
阅读目录 1.销售与客户的表结构 2.公共客户池 3.确认跟进 4.我的客户 5.code 1.销售与客户的表结构 1.公共客户与我的客户 ---公共客户(公共资源) 1.没有报名 2.3天没有跟 ...
- vue传参
<template> <ul> <li v-for="item in list" :key="item.id"> <b ...
- Java中有关Null的9件事(转)
对于Java程序员来说,null是令人头痛的东西.时常会受到空指针异常(NPE)的骚扰.连Java的发明者都承认这是他的一项巨大失误.Java为什么要保留null呢?null出现有一段时间了,并且我认 ...
- java随笔1 Ctrl+1补全
Ctrl+1补全变量时,如果补全后的不是自己想要的, 比如:补全后这样 修改后 这时要对更改变量进行Ctrl+1补全路径 并且后者要进行Ctrl+1强转
- 使用npm安装一些包失败了,更换npm源
镜像使用方法(三种办法任意一种都能解决问题,建议使用第三种,将配置写死,下次用的时候配置还在): 1.通过config命令 npm config set registry https://regist ...
- NFS配置与搭建
参考: Linux下NFS服务器的搭建与配置 https://www.cnblogs.com/liuyisai/p/5992511.html http://blog.51cto.com/hongten ...
- mysql数据库的备份和还原的总结
mysql数据库的备份和还原的总结 (来自一运维同事的总结) 1. 备份方式: 热备:数据库在线进行备份,不影响读和写的在线备份方式! 温备:数据库在线进行备份,对表备份时先锁定写操作,仅可以执行读操 ...
- Delphi中带缓存的数据更新技术
一. 概念 在网络环境下,数据库应用程序是c/s或者是多层结构的模式.在这种环境下,数据库应用程序的开发应当尽可能考虑减少网络数据传输量,并且尽量提高并发度.基于这个目的,带缓存的数据更新技术应运而生 ...
- dreamweavercs 和dreamweaver cc的區別
https://zhidao.baidu.com/question/1541178469432885667.html
- CS新建排版
1.拉菜单栏barmanage,去掉不要的头部和尾部 ,选择控件bar属性optionsbar 全部为false,防止菜单拖动. 2.拉一个panelcontrol属性dock 设置顶部,在拉一个p ...