vue实现树状表格效果

 更新时间:2020年12月29日 16:09:46   作者:保护我方豆豆  
这篇文章主要为大家详细介绍了vue实现树状表格效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了vue实现树状表格的具体代码,供大家参考,具体内容如下

1. 初始化配置

安装模块:

npm i vue-table-with-tree-grid -S

main.js 文件

import ZkTable from 'vue-table-with-tree-grid'
Vue.component(ZkTable.name, ZkTable);

2. 使用

<template lang="html">
 <div id="example">
 <zk-table
  ref="table"
  index-text="#"
  :data="data"
  :columns="columns"
  :stripe="props.stripe"
  :border="props.border"
  :show-header="props.showHeader"
  :show-summary="props.showSummary"
  :show-row-hover="props.showRowHover"
  :show-index="props.showIndex"
  :tree-type="props.treeType"
  :is-fold="props.isFold"
  :expand-type="props.expandType"
  :selection-type="props.selectionType">

  <template slot="likes" scope="scope">
  {{ scope.row.likes.join(',') }}
  </template>
 </zk-table>
 </div>
</template>

<script>

 export default {
 name: 'example',

 data() {
  return {
  props: {
   stripe: false, // 是否显示间隔斑马纹
   border: true, // 是否显示纵向边框
   showHeader: true, // 是否显示表头
   showSummary: false, // 是否显示表尾合计行
   showRowHover: true, // 鼠标悬停时,是否高亮当前行
   showIndex: true, // 是否显示数据索引
   treeType: true, // 是否为树形表格
   isFold: true, // 树形表格中父级是否默认折叠
   expandType: false, // 是否为展开行类型表格(为 True 时,需要添加名称为 '$expand' 的作用域插槽, 它可以获取到 row, rowIndex)
   selectionType: false, // 是否为多选类型表格
  },
  data: [
   {
   name: 'Jack',
   sex: 'male',
   likes: ['football', 'basketball'],
   score: 10,
   children: [
    {
    name: 'Ashley',
    sex: 'female',
    likes: ['football', 'basketball'],
    score: 20,
    children: [
     {
     name: 'Ashley',
     sex: 'female',
     likes: ['football', 'basketball'],
     score: 20,
     },
     {
     name: 'Taki',
     sex: 'male',
     likes: ['football', 'basketball'],
     score: 10,
     children: [
      {
      name: 'Ashley',
      sex: 'female',
      likes: ['football', 'basketball'],
      score: 20,
      },
      {
      name: 'Taki',
      sex: 'male',
      likes: ['football', 'basketball'],
      score: 10,
      children: [
       {
       name: 'Ashley',
       sex: 'female',
       likes: ['football', 'basketball'],
       score: 20,
       },
       {
       name: 'Taki',
       sex: 'male',
       likes: ['football', 'basketball'],
       score: 10,
       },
      ],
      },
     ],
     },
    ],
    },
    {
    name: 'Taki',
    sex: 'male',
    likes: ['football', 'basketball'],
    score: 10,
    },
   ],
   },
   {
   name: 'Tom',
   sex: 'male',
   likes: ['football', 'basketball'],
   score: 20,
   children: [
    {
    name: 'Ashley',
    sex: 'female',
    likes: ['football', 'basketball'],
    score: 20,
    children: [
     {
     name: 'Ashley',
     sex: 'female',
     likes: ['football', 'basketball'],
     score: 20,
     },
     {
     name: 'Taki',
     sex: 'male',
     likes: ['football', 'basketball'],
     score: 10,
     },
    ],
    },
    {
    name: 'Taki',
    sex: 'male',
    likes: ['football', 'basketball'],
    score: 10,
    children: [
     {
     name: 'Ashley',
     sex: 'female',
     likes: ['football', 'basketball'],
     score: 20,
     },
     {
     name: 'Taki',
     sex: 'male',
     likes: ['football', 'basketball'],
     score: 10,
     },
    ],
    },
   ],
   },
   {
   name: 'Tom',
   sex: 'male',
   likes: ['football', 'basketball'],
   score: 20,
   },
   {
   name: 'Tom',
   sex: 'male',
   likes: ['football', 'basketball'],
   score: 20,
   children: [
    {
    name: 'Ashley',
    sex: 'female',
    likes: ['football', 'basketball'],
    score: 20,
    },
    {
    name: 'Taki',
    sex: 'male',
    likes: ['football', 'basketball'],
    score: 10,
    },
   ],
   },
  ],
  columns: [
   {
   label: 'name', // 列标题名称
   prop: 'name', // 对应列内容的属性名
   width: '400px', // 列宽度
   },
   {
   label: 'sex',
   prop: 'sex',
   minWidth: '50px',
   },
   {
   label: 'score',
   prop: 'score',
   },
   {
   label: 'likes',
   prop: 'likes',
   minWidth: '200px',
   type: 'template',
   template: 'likes', // 列类型为 'template'(自定义列模板) 时,对应的作用域插槽(它可以获取到 row, rowIndex, column, columnIndex)名称
   },
  ],
  };
 },
 };
</script>

<style scoped lang="less">
 * {
 margin: 0;
 padding: 0;
 }
 .switch-list {
 margin: 20px 0;
 list-style: none;
 overflow: hidden;
 }
 .switch-item {
 margin: 20px;
 float: left;
 }
</style>

3. 效果

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • vue如何使用rem适配

    vue如何使用rem适配

    这篇文章主要介绍了vue如何使用rem适配,帮助大家处理vue开发移动应用时的兼容性问题,感兴趣的朋友可以了解下
    2021-02-02
  • vue3 tailwindcss的使用教程

    vue3 tailwindcss的使用教程

    Tailwind是由Adam Wathan领导的TailwindLabs开发的 CSS 框架,这篇文章主要介绍了vue3 tailwindcss的使用,需要的朋友可以参考下
    2023-08-08
  • vue3中如何使用d3.js绘制流程图(TS语法)

    vue3中如何使用d3.js绘制流程图(TS语法)

    这篇文章主要给大家介绍了关于vue3中如何使用d3.js绘制流程图的相关资料,D3.js是由javaScript语言编写绘图库,其原理是通过调用一系列内置函数,生成SVG,并在网页渲染,需要的朋友可以参考下
    2023-10-10
  • vue如何根据url下载非同源文件

    vue如何根据url下载非同源文件

    我们在开发过程中,有时会遇到后端返回的文件地址和我们的网站不是同源的情况下,本文就介绍了vue如何根据url下载非同源文件,感兴趣的可以了解一下
    2021-06-06
  • Vue 动态组件与 v-once 指令的实现

    Vue 动态组件与 v-once 指令的实现

    这篇文章主要介绍了Vue 动态组件与 v-once 指令的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-02-02
  • vue3中cookie的详细使用过程

    vue3中cookie的详细使用过程

    近期做的项目比较杂,涉及到前端框架的工作,遇到了许多问题,记录一下这个比较棘手的问题,下面这篇文章主要给大家介绍了关于vue3中cookie的详细使用方法,文中通过实例代码介绍的非常详细,需要的朋友可以参考下
    2022-08-08
  • vue中filters 传入两个参数 / 使用两个filters的实现方法

    vue中filters 传入两个参数 / 使用两个filters的实现方法

    这篇文章主要介绍了vue中filters 传入两个参数 / 使用两个filters的实现方法,文中给大家提到了Vue 中的 filter 带多参的使用方法,需要的朋友可以参考下
    2019-07-07
  • 在vue中使用cookie记住用户上次选择的实例(本次例子中为下拉框)

    在vue中使用cookie记住用户上次选择的实例(本次例子中为下拉框)

    这篇文章主要介绍了在vue中使用cookie记住用户上次选择的实例(本次例子中为下拉框),具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-09-09
  • vue3如何使用watch监听props中的数据

    vue3如何使用watch监听props中的数据

    在vue项目中,父子组件数据传递是最常见的场景,但是今天在开发过程中父级数据传递到子组件,控制子组件的显隐,下面这篇文章主要给大家介绍了关于vue3如何使用watch监听props中数据的相关资料,需要的朋友可以参考下
    2022-10-10
  • vue2中Print.js的使用超详细讲解(pdf、html、json、image)

    vue2中Print.js的使用超详细讲解(pdf、html、json、image)

    项目中有用到打印功能,网上就找了print.js,下面这篇文章主要给大家介绍了关于vue2中Print.js使用(pdf、html、json、image)的相关资料,文中通过代码介绍的非常详细,需要的朋友可以参考下
    2024-03-03

最新评论