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) { $(" ...
随机推荐
- Migrate MySQL database using dump and restore
kaorimatz/mysqldump-loader: Load a MySQL dump file using LOAD DATA INFILEhttps://github.com/kaorimat ...
- Spring、MyBatis、Shiro、Quartz、Activiti框架
https://www.renren.io/ 人人开源:基于Spring.MyBatis.Shiro框架,开发的一套后台脚手架框架(权限系统),极低门槛,拿来即用.支持分布式部署.Quartz分布式集 ...
- node path
1.path.basename(path[, ext]) ● path <string> ● ext <string> An optional file extension ● ...
- 关于百度地图API和jqGrid踩到的坑
1.百度地图重新标记问题 var map = new BMap.Map("map"); ...... var marker = new BMap.Marker(point); // ...
- opencv2\core\cuda.hpp(106): error C2059: 语法错误:“常量”
在 cuda.hpp 中, virtual void free(GpuMat* mat) = 0; -> virtual void _free(GpuMat* mat) = 0;
- composer更改源为国际
composer config -g repo.packagist composer https://repo.packagist.org
- centos5 安装redmine
一.下载依赖包 yum -y install libxslt-devel libyaml-devel libxml2-devel gdbm-devel libffi-devel yum -y inst ...
- Delphi中带缓存的数据更新技术
一. 概念 在网络环境下,数据库应用程序是c/s或者是多层结构的模式.在这种环境下,数据库应用程序的开发应当尽可能考虑减少网络数据传输量,并且尽量提高并发度.基于这个目的,带缓存的数据更新技术应运而生 ...
- html5 表單輸入類型
輸入類型有:email,url,number,range,Date pickers(工作機制是什麼),search, 有相關類型的輸入域,會對域進行驗證. 不同的瀏覽器並不一定都支持所有的輸入類型.
- MySQL创建远程用户并授权
今天需要在本地测试系统功能,因为本地没有数据库,就需要在程序里面连接远程数据库: 先用ssh登录远程服务器,用root连上数据库看看情况: mysql> select Host,User,Pas ...