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) { $(" ...
随机推荐
- LINUX操作系统(centos6.9)安装与配置
LINUX操作系统(centos6.9)安装与配置_百度经验 https://jingyan.baidu.com/article/acf728fd6bdba1f8e510a3f7.html cento ...
- js 精确验证身份证(地址编码、出生日期、校验位验证)
//身份证号合法性验证 //支持15位和18位身份证号 //支持地址编码.出生日期.校验位验证 function IdentityCodeValid(code) { ::::::::::::::::: ...
- Azure系列2.1.5 —— BlobOutputStream
(小弟自学Azure,文中有不正确之处,请路过各位大神指正.) 网上azure的资料较少,尤其是API,全是英文的,中文资料更是少之又少.这次由于公司项目需要使用Azure,所以对Azure的一些学习 ...
- [转帖]Windows NT 之父 - David Cutler
Windows NT 之父 - David Cutler https://www.cnblogs.com/wangwust/p/6826200.html 曾经下过 夺路狂奔的电子书 但是还没看完.. ...
- Windows 激活的简单办法(能上网)
1. 之前很多机器上面总是提示我 盗版系统看起来挺不high的 2. 还是使用之前的办法来进行激活 slmgr (之前写过) /ipk <Product Key> 安装产品密钥(替换现 ...
- debug2
调试常用功能介绍 日常java开发中实际写代码的时间并不会很多,花在整理思路,代码重构,调试bug会占用很大部分时间. 熟练掌握调试工具,了解调试相关技巧,是java开发中减少调试时间,提高效率不可或 ...
- Jmeter安装与使用(压测)
一.介绍 Apache JMeter是100%纯JAVA桌面应用程序,被设计为用于测试客户端/服务端结构的软件(例如web应用程序).它可以用来测试静态和动态资源的性能,例如:静态文件,Java Se ...
- Yii2写日志总结
方法一 批量文件配置写入日志: 1. 首先在config.php配置文件中配置log模块 如下: 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, ...
- 开发中遇到的css兼容问题
1. overflow: scroll(平台兼容) 在Mac中的Chrome浏览器中,内容不超过容器时不会出现滚动条: 在Wins中的Chorme浏览器中,内容不超过容器时也会出现滚动条. 解决方法: ...
- PLSQL过期:Your trial period for PL/SQL Developer is over .If you want to continue using this software ,you must purchase the retail version.
PLSQL过期:Your trial period for PL/SQL Developer is over .If you want to continue using this software ...