使用方法:
1.在父组件中引入"box.vue"
//import popUpBox from "./box.vue";
 
2.在父组件中注册 popUpBox
//components:{popUpBox},
 
3.放在父组件中使用
//<popUpBox></popUpBox>
 
4.调用popUpBox组件
//this.geAlert(0)
 
注:index.vue为 父组件,后者为子组件,效果图先上,可以先看是否是自己想要的组件,再选择使用
index.vue
<template>
<div>
<popUpBox ref="modal" @on-confirm="confirm">
<div slot="modal__bd">
<div class="modal_form">
<p class="txetTitle">待付款订单</p>
</div>
<p class="textFelid">您好,查看您有一笔待支付订单,可直接支付,点击下方“确认”可直接支付。</p>
</div>
</popUpBox>
</div>
</template> <script>
import popUpBox from "./box.vue"; export default {
data() {
return { };
},
components:{
//注册组件
popUpBox
},
created(){ //调用弹出层组件
this.geAlert(0) },
methods: {
geAlert(type) {
if (type === 1) this.$refs.modal.opens("alert", "南山下");
else if (type === 2)
this.$refs.modal.opens("alert", "Yan", "2407488005@qq.com");
else {
this.$refs.modal.opens("alert");
this.$refs.modal.setMaskClass("maskBack");
}
}
}
};
</script> <style lang="less" scoped>
.textFelid {
font-size: 0.6rem;
color: #000;
text-align: left;
}
.txetTitle {
font-size: 0.6rem;
color: #000;
}
.modal__bd {
padding: 0 1.6em 0.8em;
word-wrap: break-word;
word-break: break-all;
color: #999;
}
.modal__hd_text {
padding: 1.3em 1.6em 0.5em;
}
.modal__bd_text {
font-size: 0.3rem;
line-height: 1rem;
}
.modal__bd {
padding: 0 1.6em 0.8em;
word-wrap: break-word;
word-break: break-all;
color: #999;
}
</style>

box.vue

<template>
<div>
<div id="modal" v-show="showModal">
<div class="modal-mask" :class="maskBack"></div>
<div class="modal-body">
<div class="modal__hd">
<h3 class="modal__hd_text" v-if="title">{{title}}</h3>
<slot v-else name="modal__hd"></slot>
</div>
<div class="modal__bd">
<p class="modal__bd_text" v-if="msg&&type === 'alert'">{{msg}}</p>
<div v-else-if="msg&&type === 'confirm'" class="input_box">
<input type="text" :placeholder="msg" name="userid" ref="modalval" />
</div>
<slot v-else name="modal__bd"></slot>
</div>
<div v-if="type === 'confirm'" class="modal__ft flex">
<button class="btn modal__btn modal__btn_primary" @click="confirm()">支付</button>
<button class="btn modal__btn modal__btn_default" @click="closes();geAlert(0)">申请退款</button>
</div>
<div v-else-if="type === 'alert'" class="modal__ft">
<div class="btna modal__btn modal__btn_default" @click="queren()">确认</div>
<div class="btna border_right modal__btn modal__btn_default" @click="quxiao()">取消</div>
</div>
</div>
</div>
</div>
</template> <script>
export default {
data() {
return {};
},
methods: {
closes() {
this.showModal = false;
this.type = "alert";
this.title = "add";
this.msg = "";
this.maskBack = "";
},
opens(type, title, msg) {
this.showModal = true;
this.type = type;
this.title = title;
this.msg = msg;
this.$emit("oper");
},
confirm() {
this.$emit("on-confirm");
this.closes();
},
getVal() {
if (this.$refs.modalval) {
return this.$refs.modalval.value;
}
},
setMaskClass(back) {
this.maskBack = back || "maskBackNo";
}
}
};
</script> <style lang="less" scoped>
.modal-mask {
position: fixed;
z-index: 1000;
top: 0;
right: 0;
left: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.6);
}
.maskBackNo {
background: inherit;
}
.modal-body {
position: fixed;
z-index: 1000;
width: 12rem;
top: 10rem;
height: 7.3rem;
left: 50%;
transform: translate(-50%, -50%);
background-color: #fff;
text-align: center;
border-radius: 0.5rem;
overflow: hidden;
}
.modal__bd {
padding: 0 1.6em 0.8em;
word-wrap: break-word;
word-break: break-all;
color: #999;
}
.modal__hd_text {
padding: 1.3em 1.6em 0.5em;
}
.modal__bd_text {
font-size: 0.3rem;
line-height: 1rem;
} .input_box input {
height: 0.6rem;
border: 1px solid #d9d9d9;
border-radius: .1rem;
padding: 0 0.3rem;
width: 70%;
} .modal__ft {
position: fixed;
left: 0;
bottom: 0;
line-height: 0.8rem;
font-size: 0.35rem;
width: 100%;
}
.modal__ft:after {
content: " ";
position: absolute;
left: 0;
top: 0;
right: 0;
height: 1px;
border-top: 1px solid #ccc;
color: #d5d5d6;
transform-origin: 0 0; transform: scaleY(0.5);
}
.modal__btn {
position: relative;
/* display: block; */
font-size: .3rem;
color: #fff;
width: 50%;
height: 1.7rem;
/* border-radius: 1rem; */
/* margin: 0 auto; */
line-height: 1.7rem;
}
.border_right{
border-right: 1px solid #e5e5e5;
box-sizing: border-box;
}
.modal__btn_primary,
.modal__btn_alert {
background-color: #fff; /* color: #fa0; */
font-size: .6rem;
width: 50%;
}
.modal__btn_default {
color: #ffaa00;
font-size: 0.6rem;
float: right;
}
.modal__btn_alert {
width: 100%;
height: 1rem;
}
.modal__btn:after {
content: " ";
width: 200%;
height: 200%;
position: absolute;
top: 0;
left: 0;
-webkit-transform: scale(0.5);
transform: scale(0.5);
-webkit-transform-origin: 0 0;
transform-origin: 0 0;
box-sizing: border-box;
border-radius: .2rem;
}
</style>

Vue自行封装常用组件-弹出框的更多相关文章

  1. Vue自行封装常用组件-文本提示

    使用方法:1.在父组件中引入"toast.vue" //import toast from "./toast"; 2.在父组件中注册 toast //compo ...

  2. Vue自行封装常用组件-倒计时

    倒计时组件,比较复杂一点,大神勿调侃,精确到毫秒,因为项目中多次出现倒计时,所以拿出来分享下 使用方法:1.在父组件中引入"uni-countdown" //import uniC ...

  3. 基于Vue.js PC桌面端弹出框组件|vue自定义弹层组件|vue模态框

    vue.js构建的轻量级PC网页端交互式弹层组件VLayer. 前段时间有分享过一个vue移动端弹窗组件,今天给大家分享一个最近开发的vue pc端弹出层组件. VLayer 一款集Alert.Dia ...

  4. vue之element-ui设置全局弹出框

    这样的需求,在主要功能完成后,需要进行交互效果的完善,需要给请求api的时候添加一个加载中的一个弹出框.但是每个页面每个页面过的话,会很费时间和精力,这里我们可以采用element-ui中的服务式弹出 ...

  5. vue在element-ui的dialog弹出框中加入百度地图

    参考:https://blog.csdn.net/u012724595/article/details/82703579 <!-- gps弹窗 --> <el-dialog v-di ...

  6. JavaScript封装一个MyAlert弹出框

    平时我们想要显示一些提示信息时会用到alert方法,alert是全局的一个方法,会短暂的中断程序,我们主要用来显示提示客户信息.但是这个方法有一定的局限性,而且本身样式也不够美观.于是我封装了一个实用 ...

  7. elementUI vue this.$confirm 和el-dialog 弹出框 移动

    调试了好久, 还能凑合用, 请直接看DOME 示例,复制就能用: <!DOCTYPE html> <html lang="zh"> <head> ...

  8. 尝试用React写几个通用组件 - 带搜索功能的下拉列表,开关切换按钮,弹出框

    尝试用React写几个通用组件 - 带搜索功能的下拉列表,开关切换按钮,弹出框 近期正在逐步摸索学习React的用法,尝试着写几个通用型的组件,整体项目还是根据webpack+react+css-me ...

  9. [ vue ] Quasar封装q-dialog组件,在外层实现弹出框的开启和关闭

    场景描述: 见:https://www.cnblogs.com/remly/p/12981582.html 具体实现: <!-- 父组件 --> <template> < ...

随机推荐

  1. spring_quartz的实现

    一.在spring配置文件中引用对应的定时任务配置文件 二.定义定时任务的业务代码 三.配置定时任务配置文件spring-quartz.xml <?xml version="1.0&q ...

  2. 1-2、kubernetes架构概述和kubernetes基础概念

    kubernetes https://draveness.me/understanding-kubernetes http://kubernetes.kansea.com/docs/ master/n ...

  3. jdk1.8-LinkedList源码分析

    一:类的继承关系 我们看下类的继承关系 ) ) )) { ; i > index; i--) //当前记录结点等于上一节点 x = x.prev; //返回索引为index的点! return ...

  4. 利用netsh命令设置IP地址/DNS服务器地址

    一.设置IP地址 1. 自动获取IP地址: netsh interface ip set address [name=]"本地连接" [source=]dhcp 2. 手动设置IP ...

  5. ApiDoc 后端接口注释文档的使用

    前端和后端注释文档生成 前端和后端的 函数及api 说明文档生成总结,持续更新中 by Qzx 参考网址 jsDoc - 中文说明 jsDoc 使用教程 后台接口文档生成器 - APIDOC官网 ap ...

  6. 461. 汉明距离(Hamming Distance)leetcode

    首先附上题目链接: https://leetcode-cn.com/problems/hamming-distance/ 一:题目 两个整数之间的汉明距离指的是这两个数字对应二进制位不同的位置的数目. ...

  7. python smtplib server not connect

    最近发现用smtplib发邮件一直发送不成功,使用debug发现前面都正常,但是DATA发送直接被smtp服务器直接断开.smtp服务器显示body丢失. 后来发现是我加了附件,有指定文件类型: at ...

  8. python 学习笔记三 (元编程)

    #动态创建类 # type(class_name, tuple_of_parent_class, dict_of_attribute_names_and_values), 第二个参数为继承关系,可以为 ...

  9. C++类型转换(类型转换函数+类型构造函数)

    C++类型转换(类型转换函数+类型构造函数) 类型转换函数 类型转换运算符是类的一种特殊成员函数,它负责将一个类类型的值转换成其他类型. graph LR 类类型--> 类型转换函数 --> ...

  10. # 解决MongoDB突然无法连接的问题

    解决MongoDB突然无法连接的问题 使用命令,加上路径sudo mongod --dbpath=/var/lib/mongodb 这种情况一般是上一次使用的时候没有正常关闭数据库,正常启动:mong ...