vue 实现modal
本文只是作为练习弹出框,弹框内部的东西需要进行自定义添加,主要对更新,删除,新建 ,提示四种弹框进行实现,例子中只是简单的组件应用
Modal.vue文件
<template>
<div id ="modalPopBox" v-if="innerAriaShow">
<div class="el-modal-wrapper">
<div class="el-modal-box">
<div class="el-modal-header">
<span class="el-modal-title">{{ariaLabel}}</span>
<span class="close" @click="closeModal()">x</span>
</div>
<div class="el-modal-content">
<slot name="body"></slot>
</div>
<div class="el-modal-btns">
<slot name="btns"></slot>
</div>
</div>
</div>
</div>
</template>
<script>
export default{
name:'modalPopBox',
props:{
ariaLabel:{
type:String,
default:'prompt'
},
ariaShow:{
type:Boolean,
default:false
},
itemId:{
type:Number
}
},
data:function(){
return {
innerAriaShow:this.ariaShow,
updateModal:'',
deleteModal:'',
addModal:'',
promptModal:''
}
},
methods:{
closeModal:function(){
this.innerAriaShow = false;
if(this.ariaLabel=='Update'){
this.updateModal=false;
this.$emit('getUpdateModal',this.updateModal);
}
if(this.ariaLabel=='Delete'){
this.deleteModal=false;
this.$emit('getDeleteModal',this.deleteModal);
}
if(this.ariaLabel=='New'){
this.addModal = false;
this.$emit('getAddModal',this.addModal);
}
if(this.ariaLabel=='Prompt'){
this.promptModal = false;
this.$emit('getPromptModal',this.promptModal);
}
}
}
}
</script>
<style>
#modalPopBox{
position: fixed;
z-index: 9998;
top: 0;
left: 0;
width: 100%;
height: 100%;
/*background-color: rgba(0, 0, 0, .5);*/
display: table;
transition: height 2s ease;
}
.el-modal-wrapper{
display:table-cell;
vertical-align:middle;
}
.el-modal-box{
width:400px;
margin:0 auto;
border-radius:6px;
/*height:300px;*/
padding:10px 30px;
background-color:#fff;
border-radius:2px;
box-shadow:0 2px 8px ragb(0,0,0,0.33);
/*transition:all 1s ease;*/
font-family:Helvetica,Arial,sans-serif;
transition: height 2s ease;
}
.el-modal-header{
height:30px;
line-height:30px;
}
.el-modal-header .el-modal-title{
font-size:16px;
font-weight: bold;
color:#333;
}
.el-modal-header .close{
position:relative;
top:0;
left:350px;
width:30px;
height:30px;
cursor:pointer;
}
.el-modal-header .close:hover{
color:#f44;
}
.el-modal-content{
margin:0 auto;
text-align:center;
padding:10px 10px;
}
.el-modal-btns{
text-align:center;
padding:10px 0;
}
.el-modal-btns button{
/*width:60px;*/
border-radius:5px;
background-color: #409eff;
padding:6px 10px;
cursor:pointer;
color:#fff;
border-color:#409eff;
border-style:none;
} </style>
在其他组件中应用
<template>
<div id = "outletapp">
<div class="btns">
<tr class="data-tr" v-for="(item,index) in itemList">
<td class="data-td">{{item.value1}}</td>
<td class="data-td">{{item.value2}}</td>
<td class="data-td">
<button class="buttonCurd" @click="update(item)">Update</button> |
<button class="buttonCurd" @click="del(item.id)">Delete</button>
</td>
</tr>
</div>
<div class="modal-mask" v-if="updateModal">
<modal-pop-box :ariaLabel="modalName" :ariaShow=true :itemId="countInfo.itemId" @getUpdateModal="getUpdateModal">
<div slot="body">
<table>
<tr>
<td class="alignright"><label for="manage_accout">key1:</label></td>
<td class="alignleft"><input name="manage_accout" type="text" v-model="pars.value1"></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td class="alignright"><label for="queue_accout">key2:</label></td>
<td class="alignleft"><input name="queue_accout" type="text" v-model="pars.value2"></td>
</tr>
</table>
</div>
<div slot="btns">
<button type="submit" @click="updateSubmit(pars.id)">Submit</button>
</div>
</modal-pop-box>
</div>
<div class="modal-mask" v-if="deleteModal">
<modal-pop-box :ariaLabel="modalName" :ariaShow=true v-if="deleteModal" :itemId="countInfo.itemId" @getDeleteModal="getDeleteModal">
<div slot="body">
确认删除该条信息么?
</div>
<div slot="btns">
<button @click="deleteSubmit(pars.id)">确认</button>
<button @click="deleteClose()">取消</button>
</div>
</modal-pop-box>
</div>
<div class="modal-mask" v-if="promptModal">
<modal-pop-box :ariaLabel="modalName" :ariaShow=true v-if="promptModal" @getPromptModal="getPromptModal">
<div slot="body">
{{desc}}
</div>
<div slot="btns">
<button @click="closePrompt()">OK</button>
</div>
</modal-pop-box>
</div>
</div>
</template>
<script>
import modalPopBox from '../components/modal.vue'
var vm = {
data:function(){
return {
updateModal:false,
deleteModal:false,
promptModal:false,
pars:{
value1:'',
value2:'',
id:0
},
desc:'',
modalName:'',
itemList:{},
parentTotal:0,
parentCurrentPage:1,
parentPagesize:10,
queryParams:{
otherParams:'',
pagesize:10,
pageNum:1
},
}
},
methods:{
update:function(obj){
this.updateModal = true;
this.pars.itemId = parseInt(obj.id);
this.pars.value1 = obj.value1;
this.pars.value2 = obj.value2;
this.modalName = "Update"
},
del:function(idx){
this.deleteModal = true;
this.pars.id = parseInt(idx);
this.modalName = "Delete"
},
updateSubmit:function(idx){
this.pars.id=idx;
this.$http.post('',this.pars,{emulateJSON:true}).then(function(res){
this.updateModal = false;
this.parentCallback(this.queryParams);
},function(res){
this.desc= res.desc;
this.promptModal = true;
}
)
},
deleteSubmit:function(idx){
this.pars.id=idx;
this.$http.post('',this.pars.id,{emulateJSON:true}).then(function(res){
this.deleteModal = false;
this.parentCallback(this.queryParams);
},function(res){
this.desc= 'ajax failure';
this.deleteModal = false;
this.promptModal = true;
this.modalName = "Prompt"
}
)
},
deleteClose:function(){
this.deleteModal = false;
},
getUpdateModal:function(par){
this.updateModal = par;
},
getDeleteModal:function(par){
this.deleteModal = par;
},
getPromptModal:function(par){
this.promptModal = par;
},
closePrompt:function(){
this.promptModal = false;
}
},
beforeCreate:function(){
// 初始化请求一下数据,本例中使用的是本地数据
var res= jsontest2;
var tem = res;
this.itemList = tem.rows;
this.parentTotal = parseInt(tem.total);
},
created:function(){
var _self = this;
_self.parentCallback(_self.queryParams);
},
components:{
modalPopBox
}
}
export default vm
// vm.testhook = 2
</script>
<style>
.modal-mask{
position: fixed;
z-index: 9998;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(100, 100, 100, .5);
display: table;
transition: opacity 1s ease;
}
.buttonCurd{
color:#0000ff;
cursor:pointer;
}
.buttonCurd:hover{
color:#882222;
}
.alignright{
text-align:right;
padding-right:6px;
}
.alignleft{
text-align:left;
}
</style>
vue 实现modal的更多相关文章
- vue 自定义modal 模态框组件
参数名 类型 说明 visible Boolean 是否显示,默认false title String 标题 update:visible Boolean 更新visible, 使用:visible. ...
- vue iview modal弹出框 form表单验证
一.ref="addApply" :model="addApply" :rules="ruleValidate" 不要忘记prop 二. ...
- vue bootstrap中modal对话框不显示遮挡打不开
使用Vue bootstrap时,点击modal却不能弹出来,被隐藏遮挡无法显示,参考下面的这个博客的说明解决了这个问题: Heap Stack Blog(pingbook.top)Vue boots ...
- Vue.js说说组件
什么是组件:组件是Vue.js最强大的功能之一.组件可以扩展HTML元素,封装可重用的代码.在较高层面上,组件是自定义的元素,Vue.js的编译器为它添加特殊功能.在有些情况下,组件也可以是原生HTM ...
- vue.js笔记
一.v-bind 缩写 <!-- 完整语法 --> <a v-bind:href="url"></a> <!-- 缩写 --> &l ...
- Vue开源项目库汇总
最近做了一个Vue开源项目库汇总,里面集合了OpenDigg 上的优质的Vue开源项目库,方便移动开发人员便捷的找到自己需要的项目工具等,感兴趣的可以到GitHub上给个star. UI组件 elem ...
- Vue常用经典开源项目汇总参考-海量
Vue常用经典开源项目汇总参考-海量 Vue是什么? Vue.js(读音 /vjuː/, 类似于 view) 是一套构建用户界面的 渐进式框架.与其他重量级框架不同的是,Vue 采用自底向上增量开发的 ...
- Vue常用开源项目汇总
前言:Vue (读音 /vjuː/,类似于 view) 是一套用于构建用户界面的渐进式框架.与其它大型框架不同的是,Vue 被设计为可以自底向上逐层应用.Vue 的核心库只关注视图层,不仅易于上手,还 ...
- vue各种插件汇总
https://blog.csdn.net/wh8_2011/article/details/80497620(copy) Vue是什么? Vue.js(读音 /vjuː/, 类似于 view) 是一 ...
随机推荐
- Element-diag中遮罩
<el-dialog title="收货地址" :visible.sync="dialogFormVisible" append-to-body> ...
- git bash 报错bash: *: command not found
默认安装的git bash某些功能是没有的,比如zip,在git bash下执行zip和unzip命令时会报错命令找不到,但值得庆幸的是,我们可以安装我们需要的命令,以下以zip命令为例,步骤如下: ...
- [LeetCode] 100. Same Tree_Easy tag: DFS
Given two binary trees, write a function to check if they are the same or not. Two binary trees are ...
- [xdoj] 1310 DSKer的卡牌游戏
http://acm.xidian.edu.cn/problem.php?id=1310 1. 这道题可以类比括号匹配,YY和yy是两组可以匹配的信号,当然要注意逻辑是否正确,一开始进行括号匹配算法的 ...
- Express web框架
哈哈,还是Node.JS哦 现在我们来看看位Node.JS些的Express webkuangjia 一. 安装express npm install express -g --save npm in ...
- C# 指定http请求使用Tls1.2
转载于 https://blog.csdn.net/yanghaitian/article/details/77498872 客户端语言 版本 类库 是否支持 兼容方案 Java 1.6.115之 ...
- jmeter二次开发----Loadrunner或Jmeter发送邮件报告
Loadrunner支持Java Vuser,而Jmeter本身就是基于Java开发的,所以两者都可以通过JMail组件实现邮件发送.本人使用的是mail-1.4.7.jar,可以通过下载获得:htt ...
- cocos2d-x JS 加载播放Studio帧动画的两种方法
昨天懵逼的搞了两个多小时(百度无果/没看出什么矛头),自己琢磨总算搞出来了 1. var levelUpJson = ccs.load("res/LevelUp.json") ...
- eclipse 把鼠标指针放在错误的语句上 提示快速修正 不见了的解决方法
Window->Preferences->Java->Editor->Hovers 将[Combined Hover]选择即可,如果第一个[Variable Values]已经 ...
- 解决Windows内存问题的两个小工具RamMap和VMMap
解决Windows内存问题需要对操作系统的深入理解,同时对于如何运用Windows调试器或性能监控器要有工作认知.如果你正试着得到细节,诸如内核堆栈大小或硬盘内存消耗,你会需要调试器命令和内核数据架构 ...