在处理表格编辑相关的需求,是需要做一个弹框进行保存的;或者查看表格数据的详细信息时,也是需要做弹窗;

当然 ,这是类似于这样的 ,当然 element 已经帮我们做好 弹窗这一块

主要 我想记录的是 将 弹窗 做为组件,并且如果弹窗部分有请求部分的话,就到弹窗组件内部处理,相对于说解耦吧

也有子组件改变父组件传过来的 值

表格部分,也就是主要显示地方

<template>
<div class="myComponent">
<el-table :data="tableData" stripe style="width: 100%">
<el-table-column prop="date" label="日期" width="180"></el-table-column>
<el-table-column prop="name" label="姓名" width="180"></el-table-column>
<el-table-column prop="address" label="地址"></el-table-column>
<el-table-column label="操作" width="100">
<template slot-scope="scope">
<el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
<el-button type="text" size="small">编辑</el-button>
</template>
</el-table-column>
</el-table>
<!--
    弹窗组件引入
    dialogVisible : 表示 弹框是否显示 父组件 传 子组件的值
    dialogInfo : 表示 当前点击查看的数据 父组件 传 子组件的值
    update:dialogVisible : 表示 组件 点击取消关闭确定 传过来的 是否显示弹窗 子组件 传 父组件
   -->
<component-dialog :dialogVisible="dialogVisible" :dialogInfo="dialogInfo" @update:dialogVisible="dialogVisibles"></component-dialog>
</div>
</template> <script>
import componentDialog from "./components/dialog"; //引入组件
export default {
//引入组件
components: {
componentDialog
},
name: "myComponent",
data() {
return {
    //控制弹窗 显示
dialogVisible: false,
    //点击查看按钮 这条数据详细信息
dialogInfo:{},
    //table 的假数据
tableData: [
{
date: "2016-05-02",
name: "王小虎",
address: "上海市普陀区金沙江路 1518 弄"
},
{
date: "2016-05-04",
name: "张小虎",
address: "上海市普陀区金沙江路 1517 弄"
},
{
date: "2016-05-01",
name: "撸小虎",
address: "上海市普陀区金沙江路 1519 弄"
},
{
date: "2016-05-03",
name: "鞠小虎",
address: "上海市普陀区金沙江路 1516 弄"
}
]
};
},
created() {},
mounted() {},
methods: {
  //点击查看 按钮 的事件
handleClick(info) {
console.log(info);
this.dialogVisible = true;
this.dialogInfo = info
},
//子组件传 过来的 数据
dialogVisibles(v){
this.dialogVisible = v
console.log(v)
}
}
};
</script>
<style lang='scss' scoped>
</style>

弹窗组件部分

<template>
<el-dialog title="详细信息" :visible.sync="dialogVisible" :before-close="cancelDialog" >
<el-form class="form">
<el-form-item label="日期 : ">
<p>{{dialogInfo.date}}</p>
</el-form-item>
<el-form-item label="姓名 : ">
<p>{{dialogInfo.name}}</p>
</el-form-item>
<el-form-item label="地址 : ">
<p>{{dialogInfo.address}}</p>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="cancelDialog">取 消</el-button>
<el-button type="primary" @click="cancelDialog">确 定</el-button>
</div>
</el-dialog>
</template> <script>
export default {
//父组件 传 过来的 值
props: {
dialogVisible: {
type: Boolean,
default: false
},
dialogInfo: {
type: Object,
default: {}
}
},
watch: {
  //监听 弹窗显示, 可以用来写 请求接口
dialogVisible: function(newVal, oldVal) {
if (newVal) {
console.log(newVal);
}
}
},
components: {},
name: "componentDialog",
data() {
return {};
},
created() {},
mounted() {},
methods: {
//修改父组件传过来的值
cancelDialog() {
this.$emit("update:dialogVisible", false);
}
}
};
</script>
<style lang='scss' scoped>
.form{
background: #eee;
padding: 0 10px;
}
.dialog-footer{
text-align: center;
}
</style>

vue+element table的弹窗组件的更多相关文章

  1. 封装Vue Element的dialog弹窗组件

    我本没有想着说要封装一个弹窗组件,但有同行的朋友在问我,而且弹窗组件也确实在项目开发中用的比较多.思前想后,又本着样式统一且修改起来方便的原则,还是再为大家分享一个我所封装的弹窗组件吧. 其实,并不是 ...

  2. vue+element ui中select组件选择失效问题原因与解决方法

    codejing 2020-07-10 09:13:31  652  收藏 分类专栏: Web Vue Element UI 版权 .当表单form赋完值后,如果后续又对form中某一属性值进行操作如 ...

  3. vue+ element table如何给指定的单元格添加点击事件?

    今天使用vue,以及element-ui这个框架时,发现业务需要在表格里加一个连接跳转,当时立刻打开element的官网,进行查看http://element-cn.eleme.io/#/zh-CN/ ...

  4. 【vue】vue +element 搭建项目,组件之间通信

    父子组件通信 父 通过props属性给 子传递数据 子 操作 父  this.$parent.XXX 子通过$emit传递参数 或者通过vue-bus vue-bus既可以实现父子组件之间的通信,也可 ...

  5. Vue+element UI实现分页组件

    介绍 这是一个是基于element-UI的分页组件基础上,进行了二次封装的分页组件,在展示数据时,该分页组件采用了每显示一页数据,只请求当前页面的数据的请求策略,从而避免了一次性将数据全部请求所造成的 ...

  6. 解决vue element table行列不齐问题

    全局加入如下样式即可(app.vue): body .el-table th.gutter{ display: table-cell!important; }

  7. Vue+Element Table 列标红

    效果图 列方法 调用 样式

  8. vue+element ui 关闭弹窗前清空form表单的值

    this.$refs['disposeConfigsform'].resetFields();

  9. 封装React AntD的dialog弹窗组件

    前一段时间分享了基于vue和element所封装的弹窗组件(封装Vue Element的dialog弹窗组件),今天就来分享一个基于react和antD所封装的弹窗组件,反正所使用的技术还是那个技术, ...

随机推荐

  1. Spring Boot2.0以上版本EmbeddedServletContainerCustomizer被WebServerFactoryCustomizer替代

    在Spring Boot2.0以上配置嵌入式Servlet容器时EmbeddedServletContainerCustomizer类不存在,经网络查询发现被WebServerFactoryCusto ...

  2. iviewUI 前端静态页面实现增删改查分页

    完整代码部分 (仅供参考哈): <template> <div> <label prop="name"> 姓名: </label> ...

  3. 通过SharpZipLib实现文件夹压缩以及解压

    代码说明 基于SharpZipLib实现Zip压缩解压,扩展实现文件夹级别压缩解压: 项目源码:MasterChief.DotNet.Infrastructure.Zip Install-Packag ...

  4. Python——数据分析,Numpy,Pandas,matplotlib

    由于图片内容太多,请拖动至新标签页再查看

  5. 2019-11-07 微信小程序入门

    1.什么是微信小程序? 小程序是一种不需要下载安装即可使用的应用,它实现了应用“触手可及”,用户扫一扫或者搜一下即可打开应用,体现了“用完即走”的理念,用户不用关心是否安装太多应用的问题.应用将无处不 ...

  6. elasticsearch安装中文分词器插件smartcn

    原文:http://blog.java1234.com/blog/articles/373.html elasticsearch安装中文分词器插件smartcn elasticsearch默认分词器比 ...

  7. kibana自动创建索引

    一般索引按月.季或年为单位创建索引.我这里写成logstash-www-2019-03,www是URL的二级域名.格式类型完全根据自己方便就行. 当ELK集群中的索引过多时,我这里有100多个不同的日 ...

  8. 接口自动化--数据驱动(ddt)

    上次我们提到了unittest单元测试框架,运用单元测试框架unittest进行编写测试用例 但是遇到了一个问题,就是难道我一个测试点中有多个测试用例,我要每一个都要去编写一条测试用例嘛?这实在是太复 ...

  9. 爬虫篇-python爬虫中多线程的使用

    queue介绍 queue是python的标准库,俗称队列.可以直接import引用,在python2.x中,模块名为Queue.python3直接queue即可 在python中,多个线程之间的数据 ...

  10. HDU4747:Mex(线段树区间修改)

    传送门 题意: 给出\(n\)个数,然后求\(\sum_{i=1}^n\sum_{j=i}^nmex(i,j)\).\(mex(i,j)\)表示区间\([i,j]\)的\(mex\). 思路: 考虑枚 ...