如何使用 vxe-table 实现左边是树右边是表格联动功能
作者:可不简单
使用 vxe-table 来实现左边是树,右边是表格联动功能,当需要实现左右两侧联动时,表格 vxe-grid 配合分割模板 vxe-split 就很容易实现了,下面通过实例代码给大家介绍使用 vxe-table 来实现左边是树,右边是表格联动功能,感兴趣的朋友一起看看吧
使用 vxe-table 来实现左边是树,右边是表格联动功能,当需要实现左右两侧联动时,表格 vxe-grid 配合分割模板 vxe-split 就很容易实现了
查看官网:https://vxetable.cn
gitbub:https://github.com/x-extends/vxe-table
gitee:https://gitee.com/x-extends/vxe-table
预览
代码
<template> <div> <vxe-split height="600" border padding> <vxe-split-item width="200" min-width="100"> <vxe-tree v-bind="treeOptions" @current-change="currentChangeEvent"></vxe-tree> </vxe-split-item> <vxe-split-item min-width="300"> <vxe-grid v-bind="gridOptions"></vxe-grid> </vxe-split-item> </vxe-split> </div> </template> <script> import XEUtils from 'xe-utils' export default { data () { const treeOptions = { transform: true, keyField: 'id', parentField: 'parentId', titleField: 'title', nodeConfig: { isHover: true, isCurrent: true }, data: [ { title: '节点2', id: '2', parentId: null }, { title: '节点3', id: '3', parentId: null }, { title: '节点3-1', id: '31', parentId: '3' }, { title: '节点3-2', id: '32', parentId: '3' }, { title: '节点3-2-1', id: '321', parentId: '32' }, { title: '节点3-2-2', id: '322', parentId: '32' }, { title: '节点3-3', id: '33', parentId: '3' }, { title: '节点3-3-1', id: '331', parentId: '33' }, { title: '节点3-3-2', id: '332', parentId: '33' }, { title: '节点3-3-3', id: '333', parentId: '33' }, { title: '节点3-4', id: '34', parentId: '3' }, { title: '节点4', id: '4', parentId: null }, { title: '节点4-1', id: '41', parentId: '4' }, { title: '节点4-1-1', id: '411', parentId: '42' }, { title: '节点4-1-2', id: '412', parentId: '42' }, { title: '节点4-2', id: '42', parentId: '4' }, { title: '节点4-3', id: '43', parentId: '4' }, { title: '节点4-3-1', id: '431', parentId: '43' }, { title: '节点4-3-2', id: '432', parentId: '43' }, { title: '节点5', id: '5', parentId: null } ] } const gridOptions = { border: true, loading: false, showOverflow: true, height: '100%', columns: [ { field: 'seq', type: 'seq', width: 70 }, { field: 'name', title: 'Name' }, { field: 'sex', title: 'Sex' }, { field: 'age', title: 'Age' } ], data: [] } return { treeOptions, gridOptions } }, created () { this.loadRightList() }, methods: { loadRightList () { // 模拟后端接口 this.gridOptions.loading = true setTimeout(() => { const list = [ { id: 10001, name: 'Test1', role: 'Develop', sex: 'Man', age: 28, address: 'test abc' }, { id: 10002, name: 'Test2', role: 'Test', sex: 'Women', age: 22, address: 'Guangzhou' }, { id: 10003, name: 'Test3', role: 'PM', sex: 'Man', age: 32, address: 'Shanghai' }, { id: 10004, name: 'Test4', role: 'Designer', sex: 'Women', age: 24, address: 'Shanghai' }, { id: 10005, name: 'Test5', role: 'PM', sex: 'Man', age: 44, address: 'Shanghai' }, { id: 10006, name: 'Test6', role: 'Designer', sex: 'Women', age: 28, address: 'Guangzhou' }, { id: 10007, name: 'Test7', role: 'PM', sex: 'Man', age: 46, address: 'test abc' }, { id: 10008, name: 'Test8', role: 'Designer', sex: 'Women', age: 38, address: 'Shanghai' } ] this.gridOptions.data = XEUtils.sample(list, XEUtils.random(1, 5)) this.gridOptions.loading = false }, 200) }, currentChangeEvent () { this.loadRightList() } } } </script>
https://gitee.com/x-extends/vxe-table
到此这篇关于使用 vxe-table 来实现左边是树,右边是表格联动功能的文章就介绍到这了,更多相关MySQL JSON 查询内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!