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) 是一 ...
随机推荐
- IE8.0如何关闭启用内存保护帮助减少联机攻击?
默认情况下,该选项卡是灰色的(表示用户不能直接修改),win7电脑可以通过“以管理员身份”运行 IE 来放开该功能,但个别电脑即便用这种方法仍无法解决,此时,您可以试试如下方法: 1.在“运行”框中输 ...
- testetest
resumeLoad renren静态 foolday \ swImg activity01
- Build a Basic CRUD App with Vue.js and nodejs
https://developer.okta.com/blog/2018/02/15/build-crud-app-vuejs-node#add-authentication-with-okta I’ ...
- ABAP 创建function model 返回参数为内表类型
1:通过T-CODE se11 创建一个structure ZSTRU2. 2: 创建一个table type, 表名 ZTAB1. 3: 表的row type 选择 ZSTRU2 4: ...
- es7新特性 includes用法
返回数组是否包含某个元素 var array1 = [1, 2, 3]; console.log(array1.includes(2)); // expected output: true
- iot-hub运行在虚拟上
ng build gradlew build java -jar iot-hub-0.0.1-SNAPSHOT.jar 后台运行 nohup java -jar iot-dm-0.0.1-SNAP ...
- canvas 写一个刮刮乐抽奖
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Mac Maven配置
Maven下载链接,解压到指定目录,我这里是 /Users/JYH/Desktop/Hadoop-2.7.2/apache-maven-3.3.9 打开终端,配置环境变量 输入命令 vi ~/.bas ...
- leetcode 343 整数拆分
1.这个题拿到之后没有什么思路,此时就应该考虑暴力法.然而每次不知道要拆成几份,没办法用循环,所以想到用递归. 如图所示进行递归,显然有很多重复的计算,所以用自底向上的动态规划. 2.还有一个问题就是 ...
- TextBox显示提示信息
属性placeholder可以设置TextBox 提示信息如: <asp:TextBox ID ="txt1" runat ="server" Tool ...