使用方法:
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. LoadRunner参数化详解

    LoadRunner参数化详解 距离上次使用loadrunner 已经有一年多的时间了.初做测试时在项目中用过,后面项目中用不到,自己把重点放在了工具之外的东西上,认为性能测试不仅仅是会用工具,最近又 ...

  2. Spark3.0 preview预览版尝试GPU调用(本地模式不支持GPU)

    Spark3.0 preview预览版可以下载使用,地址:https://archive.apache.org/dist/spark/spark-3.0.0-preview/,pom.xml也可以进行 ...

  3. flask 框架快速入门

    flask 框架快速入门 搭建一个简易flask项目 首先使用 Pycharm创建flask项目 运行flask项目 1.使用Pycharm搭建flask项目 (如果Pycharm新建项目中未出现该图 ...

  4. 【AMAD】transitions -- 一个python实现的轻量级,面向对象的有限状态机

    简介 个人评分 简介 Transitions1是使用python实现的有限状态机2. 而有限状态机是实现经典模式 -- 状态模式3的前提. 这个库的API相当优雅,简洁. 另外博客园有人发布博客4介绍 ...

  5. Ubuntu18.04两步纯小白傻瓜无脑式安装Caffe

    前言 Ubuntu16安装caffe过于繁琐,然而Ubuntu18安装起来却仅仅两步而已 附上官方安装教程:http://caffe.berkeleyvision.org/install_apt.ht ...

  6. 谈一谈 Normalize.css

    Normalize.css是一种CSS reset的替代方案.它在默认的HTML元素样式上提供了跨浏览器的高度一致性.相比于传统的CSS reset,Normalize.css是一种现代的.为HTML ...

  7. IIS调试

    点击调试程序的时候默认启动TFS内置的调试服务器http://localhost:51607/,在该处填写自己在IIS上配置的站点就能进入自己的站点调试http://mr.ciwong.com

  8. 搭建elk集群 disabled in libcurl elasticsearch-6.2.2 更新license 版本

    0.logstash的部分配置 output { stdout {codec => rubydebug} elasticsearch { hosts => ["172.31.25 ...

  9. [Python3] 041 文件 持久化

    目录 文件 持久化 1. pickle 1.1 例子1 1.2 例子2 1.3 注意 2. shelve 2.1 举例 2.2 特性 2.3 强制写回 2.4 使用 with 管理上下文环境 文件 持 ...

  10. [转帖]CENTOS6.6下mysql5.7.11带boost和不带boost的源码安装

    CENTOS6.6下mysql5.7.11带boost和不带boost的源码安装 本文来自我的github pages博客http://galengao.github.io/ 即www.gaohuir ...