vue+element-ui实现表格里嵌套表格

2023-11-04

 

效果图:点击某行数据展开另一个嵌套在里面的table

核心代码:

从后台请求的数据格式:

代码实现:

<template>
  <div>
    <div class="assetnum">
      <div class="assetbox br pr30">
        <div class="assettitle">
          <span>
            已发现资产(数量:
            <strong>{{tableData2.length}}</strong>)
          </span>
        </div>
        <div class="mytable">
          <el-table ref="table2" :data="tableData2" style="width: 100%">
            <el-table-column width="50">
              <template slot-scope="scope">
                <i class="iconfont icon-tubiaozhizuomoban" @click="toogleExpand2(scope.row)"></i>
              </template>
            </el-table-column>
            <el-table-column class="sectable" prop="items" type="expand" width="1">
              <template slot-scope="scope">
                <el-table :data="scope.row.items" stripe style="width: 100%">
                  <el-table-column type="index"></el-table-column>
                  <el-table-column prop="port" label="端口"></el-table-column>
                  <el-table-column prop="protocol" label="协议"></el-table-column>
                  <el-table-column prop="service" label="服务"></el-table-column>
                  <el-table-column prop="software" label="软件"></el-table-column>
                </el-table>
              </template>
            </el-table-column>
            <el-table-column label="IP" prop="ip">
              <template slot-scope="scope">
                <span class="ipbtn">IP</span>
                {{scope.row.ip}}
              </template>
            </el-table-column>
            <el-table-column label="资产类型" prop="catagory">
              <template slot-scope="scope">
                <span v-if="scope.row.catagory=='host'">
                  <i class="iconfont icon-zhuji1"></i>
                </span>
                <span v-if="scope.row.catagory=='db'">
                  <i class="iconfont icon-weibiaoti-database"></i>
                </span>
                {{scope.row.catagory}}
              </template>
            </el-table-column>
            <el-table-column label="标准系统" prop="type">
              <template slot-scope="scope">
                <span v-if="scope.row.type=='windows'">
                  <img src="../../../../assets/img/windows.png" alt />
                </span>
                <span v-if="scope.row.type=='RedHat'">
                  <img src="../../../../assets/img/redhat.png" alt />
                </span>
                <span v-if="scope.row.type=='mysql'">
                  <img src="../../../../assets/img/Oracle.png" alt />
                </span>
                <span v-if="scope.row.type=='CentOS'">
                  <img src="../../../../assets/img/centos.png" alt />
                </span>
                {{scope.row.type}}
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div class="assetbox pl30">
        <div class="assettitle">
          <span>
            不存活资产(数量:
            <strong>{{tableData3.length}}</strong>)
          </span>
        </div>
        <div class="mytable">
          <el-table ref="table" :data="tableData3" style="width: 100%">
            <el-table-column width="50">
              <template slot-scope="scope">
                <i class="iconfont icon-tubiaozhizuomoban" @click="toogleExpand(scope.row)"></i>
              </template>
            </el-table-column>
            <el-table-column class="sectable" type="expand" width="1">
              <template>
                <el-table :data="tableData3.items" stripe style="width: 100%">
                  <el-table-column type="index"></el-table-column>
                  <el-table-column prop="port" label="端口"></el-table-column>
                  <el-table-column prop="xy" label="协议"></el-table-column>
                  <el-table-column prop="server" label="服务"></el-table-column>
                  <el-table-column prop="software" label="软件"></el-table-column>
                </el-table>
              </template>
            </el-table-column>
            <el-table-column label="IP" prop="ip">
              <template slot-scope="scope">
                <span class="ipbtn">IP</span>
                {{scope.row.ip}}
              </template>
            </el-table-column>
            <el-table-column label="资产类型" prop="catagory">
              <template slot-scope="scope">
                <span v-if="scope.row.catagory=='host'">
                  <i class="iconfont icon-zhuji1"></i>
                </span>
                <span v-if="scope.row.catagory=='db'">
                  <i class="iconfont icon-weibiaoti-database"></i>
                </span>
                {{scope.row.catagory}}
              </template>
            </el-table-column>
            <el-table-column label="标准系统" prop="type">
              <template slot-scope="scope">
                <span v-if="scope.row.type=='windows'">
                  <img src="../../../../assets/img/windows.png" alt />
                </span>
                <span v-if="scope.row.type=='RedHat'">
                  <img src="../../../../assets/img/redhat.png" alt />
                </span>
                <span v-if="scope.row.type=='Oracle'">
                  <img src="../../../../assets/img/Oracle.png" alt />
                </span>
                <span v-if="scope.row.type=='CentOS'">
                  <img src="../../../../assets/img/centos.png" alt />
                </span>
                {{scope.row.type}}
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div></div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      value2: [],
      value3: [],
      tableData2: [],
      tableData3: [],
    };
  },
  activated() {
    this.getDataList();
  },
  methods: {
    toogleExpand(row) {
      let $table = this.$refs.table;
      $table.toggleRowExpansion(row);
    },
    toogleExpand2(row) {
      let $table = this.$refs.table2;
      $table.toggleRowExpansion(row);
      console.log(this.$route.params.taskId)
    },
    getDataList(){
      //获取上一层页面点击要查看的任务ID
      var ids = this.$route.params.taskId;
      //发送请求给后台
      this.$http({
        url: this.$http.adornUrl("/ads/task/detail"),
        method: "get",
        params: this.$http.adornParams({
          taskId: ids
        })
      }).then(({ data }) => {

        if (data && data.code === 0) {
          let arr1 = data.data;
          let hadData = [];
          let noData = [];
          //对获取的数据利用status判断进行分类,再放进两个不同的数组中
          arr1.map(function(item,index){
            if(item.status == 1){
              hadData.push(item)
            }else{
              noData.push(item)
            }
          })
          //赋值给已发现资产
            this.tableData2 = hadData ;
          //赋值给不存活资产
            this.tableData3 = noData ;
            console.log(this.tableData2)
        } else {
        }
      });
    }
  }
};
</script>

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

vue+element-ui实现表格里嵌套表格 的相关文章

随机推荐

  • 14:00面试,14:08就出来了,问的问题有点变态

    从小厂出来 没想到在另一家公司又寄了 到这家公司开始上班 加班是每天必不可少的 看在钱给的比较多的份上 就不太计较了 没想到8月一纸通知 所有人不准加班 加班费不仅没有了 薪资还要降40 这下搞的饭都吃不起了 还在有个朋友内推我去了一家互联
  • pgsql备份工具:pg_rman在Linux下的安装、设置与使用

    pg rman是PostgreSQL的在线备份和恢复工具 pg rman项目的目标是提供一种像pg dump一样简单的在线备份和PITR方法 它就是pgsql实现全量备份和增量备份的最简易的工具 github地址 https github
  • 关于C语言printf输出颜色的问题.

    define NONE 033 m define RED 033 0 32 31m define LIGHT RED 033 1 31m define GREEN 033 0 32 32m define LIGHT GREEN 033 1
  • CV计算机视觉核心08-目标检测yolo v3(coco数据集)

    CV计算机视觉核心08 目标检测yolo v3 对应代码文件下载 https download csdn net download m0 37755995 86237192 需要自己下载coco的train2014和val2014 http
  • VirtualBox如何添加ISO文件或物理光盘

    最近学习Linux 想先在虚拟机上操作练练手 装个CentOS distribution 但是一开始捣鼓的时候发现 VirtualBox似乎只支持vmdk等类型的文件 但我下的是iso镜像文件啊 相信大家也可能遇到或者将会遇到这个问题 这可
  • 详解批量梯度下降法(BGD)、随机梯度下降法(SGD)和小批量梯度下降法(MBGD)

    在应用机器学习算法时 我们常采用梯度下降法来对才用的算法进行训练 梯度下降法有三种不同的形式 批量梯度下降 Batch Gradient Descent 随机梯度下降 Stochastic Gradient Descent 以及小批量梯度下
  • android 导入modoule_Android Studio中导入module的方法(简单版)

    1 把要导入成Mudle的项目修改成符合Library的格式 修改该项目中bulid gradle文件中第一行代码 把 apply plugin com android application 修改为 apply plugin com an
  • 强烈推荐的几款实用的IDEA插件(通俗易懂)

    IDEA官网插件离线下载地址 JProfiler 启动完成会自动弹出JProfiler窗口 在里面就可以监控自己的代码性能了 JProfiler 操作指南详解 点击此处跳转 EasyCode 使用Easy Code可以自动化生产后台基础逻辑
  • php 数组元素快速去重

    1 使用array unique方法进行去重 对数组元素进行去重 我们一般会使用array unique方法 使用这个方法可以把数组中的元素去重 1 2 3 4 5 6 1 2 3 4 5 6 输出 Array 0 gt 1 1 gt 2
  • 总结磁共振成像的脑龄预测的人工智能模型

    脑龄预测的人工智能模型 介绍 基于神经影像的BA预测 BA预测建模 从统计方法到DL 统计方法 使用统计 最大似然估计方法的BA研究的主要结果 深度学习 使用DL方法进行BA研究的主要结果 可解释的人工智能 即可解释的深度学习方案 可解释的
  • 从简入难makefile文件编写,Linux C++编程,简单vi命令

    1 一个最基本的C 程序 2 第二个c 程序 3 第一个入门级别的简单的makefile 4 在makefile中定义变量 5 编写makefile的依赖 如果start 标识后面的某个 o没有 则重新编译没有编译的那个文件 6 最终的ma
  • 连接git仓库失败解决办法

    问题出现 首先是我在本地建了个项目 写完了之后呢打算用sourceTree推到gitlab的仓库里 奈何这gitlab仓库怎么也连接不上 基于我是第一次使用sourceTree 想着是不是啥东西没配置好 结果各种捣鼓发现gitee和gith
  • vertx文章系列--响应式Mysql操作入门体验

    官网地址 https vertx io 中文文档 https vertx china gitee io Mysql驱动连接练习 https vertx china gitee io docs vertx mysql client java
  • CVPR2018-SRMD-Kai Zhang

    https github com cszn SRMD https github com 2wins SRMD pytorch 创新点 1 设计了一个非盲单一 CNN 网络SRMD 针对多个退化模型 模型的输入除了LR图 还有 degrati
  • Unity UI上的物体跟随场景物体位置变化而变化(人物血条/称号)

    首先看下UI上物体的位置计算 UI上的物体 以下用 血条 代称 这个很简单 无非就是坐标转换 把人物的世界坐标转到屏幕坐标 代码如下 public Transform target public Transform hpSp public
  • Linux系统安装Java

    1 下载JDK 下载网址 https www oracle com technetwork java javase downloads index html 下拉 找到jdk8 使用Xshell远程连接虚拟机 2 先新建一个文件夹 目录是
  • oracle 分区表插入数据_Oracle数据库分区表整理笔记

    关键词 partition 分区subpartition 辅助分区已经存在的表没有方法可以直接转化为分区表 分区索引 一 分区表类型 1 范围分区 1 1 按指定要求划分 假设有一个CUSTOMER表 表中有数据200000行 我们将此表通
  • JS reduce 用法

    定义 reduce 方法接收一个函数作为累加器 数组中的每个值 从左到右 开始缩减 最终计算为一个值 语法 array reduce function total currentValue currentIndex arr initialV
  • HEVC对场编码的支持

    HEVC值得注意的是它没有提供专用于隔行视频的工具 而是将隔行视频的一帧看作两个独立的场 对各个场数据分别进行编码 简化了编码器的实现 这也是因为随着数字视频技术的快速发展 视频的隔行扫描方式日渐式微 https blog csdn net
  • vue+element-ui实现表格里嵌套表格

    效果图 点击某行数据展开另一个嵌套在里面的table 核心代码 从后台请求的数据格式 代码实现