定义模态框:合理使用插槽

model.vue

<!-- 模态弹窗 -->
<template>
<div class="self-modal" v-show='showModal' @click="cancelClick" v-bind:style="styleObj" @touchmove.stop.prevent>
<!-- 自定义内容 -->
<slot></slot>
</div>
</template>
<script>
export default {
name: 'selfModal',
data () {
return {
showModal: false
}
},
props: {
styleObj: { // 用于承接样式类
type: Object,
default: function () {
return {
position: 'fixed',
bottom: 0,
top: 0,
left: 0,
width: '100%',
background: 'rgba(113,111,111,0.5)'
}
}
}
},
methods: {
// 确定
sureClick () {
this.showModal = true
return new Promise(function (resolve) {
resolve('sure')
}, function (reject) {})
},
// 取消
cancelClick () {
this.showModal = false
return new Promise(function (resolve) {
resolve('cancel')
}, function (reject) {})
}
}
}
</script>
<style scoped lang='scss'>
.self-modal{
z-index: 3000;
}
</style>

正确的使用方式:

import selfModal from '@/base/selfModal/modal'

<selfModal ref="incomeSelect" :styleObj="styleObj">
<div class="career-content" @click.prevent.stop>
<div class="mark-title">
请选择年收入
</div>
<div class="mark-wrapper" @click.stop="getIncome('1')">
<p class="nav-mark no-sub-mark">小于10万</p>
</div>
<div class="mark-wrapper" @click.stop="getIncome('2')">
<p class="nav-mark no-sub-mark">10万-30万</p>
</div>
<div class="mark-wrapper " @click.stop="getIncome('3')">
<p class="nav-mark no-sub-mark">大于30万</p>
</div>
<div class="mark-wrapper no-border-bottom">
<p class="btn-mark" @click.stop="getIncome()">取消</p>
</div>
</div>
</selfModal>
 
data () {
styleObj: {
position: 'fixed',
bottom: 0,
top: 0,
left: 0,
background: 'rgba(113, 111, 111, 0.5)',
width: '100%'
},
}
methods () {
  

selectIncome () {
  this.$refs.incomeSelect.showModal = true
}

使用插槽,实现弹框内容自定义,样式自定义,  

vue2.0实现一个模态弹框,内容自定义(使用slot)的更多相关文章

  1. 简单实现弹出弹框页面背景半透明灰,弹框内容可滚动原页面内容不可滚动的效果(JQuery)

    弹出弹框 效果展示 实现原理 html结构比较简单,即: <div>遮罩层 <div>弹框</div> </div> 先写覆盖显示窗口的遮罩层div.b ...

  2. 基于vue2.0的一个豆瓣电影App

    1.搭建项目框架 使用vue-cli 没安装的需要先安装 npm intall -g vue-cli 使用vue-cli生成项目框架 vue init webpack-simple vue-movie ...

  3. vue2.0中ckeckbox(复选框)的使用心得,及对click事件和change的理解

    最近在公司项目中使用vue2.0做开发,在使用checkbox时遇到了一些问题,首先我们先了解一下需求. 如上如所示,在上方复选框被点击时,更改下方p标签的文本内容为:复选框已被选中.并将p标签文字颜 ...

  4. jquery EsayUi 里一个小弹框

    网站后台大多的数据展示就都用和此插件有着密切的关系: 来用一下这个小弹框吧: 一个Html里面的代码 <link rel='stylesheet' type='text/css' href='c ...

  5. Vue1.x 到Vue2.0的一个变化

    小弟初来乍到,写的不好的地方还望指正.谢谢各位! 废话不多说  进入正题: Vue1.x到2.0的一个变化 1. 在每个组件模板,不在支持片段代码  组件中模板: 之前:     <templa ...

  6. layer插件学习——弹框(自定义页)

    本文是自己整理的关于layer插件的弹框样式结果 介绍: 官方介绍:layer至今仍作为layui的代表作,受众广泛并非偶然,而是这五年多的坚持,不断完善和维护.不断建设和提升社区服务,使得猿们纷纷自 ...

  7. html、css和js原生写一个模态弹出框,顺便解决父元素半透明子元素不透明效果

    模态框: html部分: <!-- 按钮 --> <button id="box" onclick="pop_box()">弹出框< ...

  8. 分享一个Web弹框类

    using System; using System.Text; namespace Core { /// <summary> /// MessageBox 的摘要说明. /// < ...

  9. 基于vue2.0的一个系统

    前言 这是一个用vue做的单页面管理系统,这里只是介绍架子搭建思路 前端架构 沿用Vue全家桶系列开发,主要技术栈:vue2.x+vue-router+vuex+element-ui1.x+axios ...

随机推荐

  1. 防止putty的鼠标右键错误粘贴

    一.环境 发行版:Ubuntu 18.04.1 LTS 代号:bionic 内核版本:4.15.0-30-generic 二.背景 每次从putty复制时,会单击鼠标右击,以便复制出终端的内容,但是一 ...

  2. 【spring-boot】 springboot整合quartz实现定时任务

    在做项目时有时候会有定时器任务的功能,比如某某时间应该做什么,多少秒应该怎么样之类的. spring支持多种定时任务的实现.我们来介绍下使用spring的定时器和使用quartz定时器 1.我们使用s ...

  3. java 23种设计模式,一般情况下,常用的有哪些? 转载

    原址:http://wangle.iteye.com/blog/196972 工厂模式, 工厂方法模式,单例模式, 外观(Facade)模式, 观察者(Observer)模式,桥接(Bridge)模式 ...

  4. tp5.1 Env使用

    5.1版本取消了所有的系统常量,原来的系统路径变量改为使用Env类获取(需要引入think\facade\Env) echo "app_path=========".Env::ge ...

  5. vue之双绑实现

    // html <body> <div id="app"> <input type="text" v-model="nu ...

  6. git-it 教程,一些git知识点。/ 如何解决merge conflict/ 如何使用Github Pages./Git术语表

    一个git使用教程 https://:.com/jlord/git-it-electron#what-to-install 一个在线Github的功能教学:https://lab.github.com ...

  7. zoj3261变形并查集

    需要变形的并查集,这题错了好久,一直没a掉,终于在重写第三次的时候a了 先保存数据,把不需要拆分的边合并,逆向计算,需要拆分时就合并,之前不知道为啥写搓了,tle好久 #include<map& ...

  8. 005PHP文件处理——目录操作,统计大小 filesize unlink

    <?php /* 目录操作,统计大小 filesize unlink * */ $dir = dir("."); while (($file = $dir->read( ...

  9. hdu 3682 10 杭州 现场 C To Be an Dream Architect 容斥 难度:0

    C - To Be an Dream Architect Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &a ...

  10. hdu5618

    题解: CDQ分治 三重分治 第一重排序 第二重CDQ 第三重树状数组 代码: #include<cstdio> #include<cmath> #include<cst ...