vue中的树形表格

实现效果

在这里插入图片描述

树形数据的结构

[{
    id: 'd4ffbce3084b7fbc351ae20482af6686',
    pid: '',
    content: '水果',
    states: 0,
    price: 0,
    children: [
      {
        id: '7240ad50e5bf1c2b158ba117bd61a362',
        pid: 'd4ffbce3084b7fbc351ae20482af6686',
        content: '苹果',
        states: 0,
        price: 10
      }, {
        id: '74768f31c97ed831cc20d7ca3cc5fe40',
        pid: 'd4ffbce3084b7fbc351ae20482af6686',
        content: '橘子',
        states: 1,
        price: 30
      }
    ]
  }
]

代码实现

keyPoints:

使用vue-table-with-tree-grid

使用方法:
1.安装依赖:npm i vue-table-with-tree-grid -S
2.main.js中全局引入和注册

import Vue from 'vue'
import ZkTable from 'vue-table-with-tree-grid'
Vue.use(ZkTable)

3.使用
模板:

<zk-table class="tree-table"
      sum-text="总和"
      :data="labelList"
      :columns="columns"
      border
      stripe
      show-row-hover
      show-index
      show-summary
      :selection-type="false"
      :expand-type="false"
      :is-fold="false"
      index-text="#"
>
	<!-- 是否有效 -->
	<template slot="isOk" slot-scope="scope">
		<i v-if="!scope.row.states" class="el-icon-success" style="color:lightgreen" />
		<i v-else class="el-icon-error" style="color:#F56C6C" />
	</template>
	<!-- 排序层级 -->
	<template slot="level" slot-scope="scope">
		<el-tag v-if="scope.row.pid.trim().length===0" size="mini">
		  一级
		</el-tag>
		<el-tag v-else size="mini" type="warning">
		  二级
		</el-tag>
	</template>
	<!-- 操作 -->
	<template slot="opt" slot-scope="scope">
		<el-button circle type="primary" size="mini" icon="el-icon-edit-outline"
		           @click="EditLabel(scope.row)"
		/>
	</template>
</zk-table>

js:

data () {
	return {
	  // 标签列表数据
	  labelList: [
	    {
	      id: 'd4ffbce3084b7fbc351ae20482af6686',
	      pid: '',
	      content: '水果',
	      states: 0,
	      price: 0,
	      children: [
	        {
	          id: '7240ad50e5bf1c2b158ba117bd61a362',
	          pid: 'd4ffbce3084b7fbc351ae20482af6686',
	          content: '苹果',
	          states: 0,
	          price: 10
	        }, {
	          id: '74768f31c97ed831cc20d7ca3cc5fe40',
	          pid: 'd4ffbce3084b7fbc351ae20482af6686',
	          content: '橘子',
	          states: 1,
	          price: 30
	        }
	      ]
	    }
	  ],
	
	  // 列表的列的配置项
	  columns: [
	    {
	      label: '标签名称',
	      prop: 'content'
	    },
	    {
	      label: '价格',
	      prop: 'price'
	    },
	    {
	      label: '是否有效',
	      type: 'template',// 将当前列定义为模板列
	      template: 'isOk'// 当前这一列使用模板名称
	    },
	    {
	      label: '排序',
	      type: 'template',
	      template: 'level'
	    },
	    {
	      label: '操作',
	      type: 'template',
	      template: 'opt'
	    }
	  ]
	}
}

官方地址:vue-table-with-tree-grid

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值