1. Achieve results2. Backend implementation2.1 Entity Class@Data @ApiModel(description = "data dictionary") @TableName("dict") public class Dict { private static final long serialVersionUID = 1L; @ApiModelProperty(value = "id") private Long id; @ApiModelProperty(value = "creation time") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @TableField("create_time") private Date createTime; @ApiModelProperty(value = "update time") @TableField("update_time") private Date updateTime; @ApiModelProperty(value = "Logical deletion (1: deleted, 0: not deleted)") @TableLogic @TableField("is_deleted") private Integer isDeleted; @ApiModelProperty(value = "other parameters") @TableField(exist = false) private Map<String,Object> param = new HashMap<>(); @ApiModelProperty(value = "superior id") @TableField("parent_id") private Long parentId; @ApiModelProperty(value = "name") @TableField("name") private String name; @ApiModelProperty(value = "value") @TableField("value") private String value; @ApiModelProperty(value = "encoding") @TableField("dict_code") private String dictCode; @ApiModelProperty(value = "Whether to include child nodes") @TableField(exist = false) private boolean hasChildren; } The above must include a hasChildren property, even if it does not exist in the database. This is required by the element framework. 2.2 Data Structure in the Database2.3 Backend interfaceIf it is implemented entirely on the backend, then just write a recursive query to query all the data according to the hierarchical structure and encapsulate it. But the table component of element has encapsulated some things for us. We only need to query the sub-data list according to the parent ID here. Controller code: //Query the sub-data list according to the parent id @ApiOperation(value = "Query the sub-data list according to the parent id") @GetMapping("findChildData/{id}") public Result findChildData(@PathVariable Long id){ List<Dict> list = dictService.findChildData(id); return Result.ok(list); } service Service implementation class @Service public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements DictService { //Query the sub-data list according to the parent id @Override public List<Dict> findChildData(Long id) { QueryWrapper<Dict> wrapper=new QueryWrapper<>(); wrapper.eq("parent_id",id); List<Dict> list = baseMapper.selectList(wrapper); //Set hasChildren to each dict object in the list collection list.forEach(x->{ Long dictId = x.getId(); boolean isChild = this.isChildren(dictId); x.setHasChildren(isChild); }); return list; } //Judge whether there is child data under id private boolean isChildren(Long id){ QueryWrapper<Dict> wrapper=new QueryWrapper<>(); wrapper.eq("parent_id",id); Integer count = baseMapper.selectCount(wrapper); return count > 0; } } 2.4 Swagger tests whether the backend structure and function are normal3. Front-end implementation3.1 Introducing el-table component into the pagelist.vue <template> <div class="app-container"> <el-table :data="list" style="width: 100%" row-key="id" border lazy :load="getChildrens" :tree-props="{children: 'children', hasChildren: 'hasChildren'}"> <el-table-column label="Name" width="230" align="left"> <template slot-scope="scope"> <span>{{ scope.row.name }}</span> </template> </el-table-column> <el-table-column label="Encoding" width="220"> <template slot-scope="{row}"> {{ row.dictCode }} </template> </el-table-column> <el-table-column label="value" width="230" align="left"> <template slot-scope="scope"> <span>{{ scope.row.value }}</span> </template> </el-table-column> <el-table-column label="Creation time" align="center"> <template slot-scope="scope"> <span>{{ scope.row.createTime }}</span> </template> </el-table-column> </el-table> </div> </template> <script> import dict from '@/api/dict' export default { name: 'list', data(){ return { list:[], //data dictionary list array dialogImportVisible:false, //set whether the pop-up box pops up} }, created() { this.getDictList(1) }, methods:{ //Data dictionary list getDictList(id){ dict.dictList(id) .then(response=>{ this.list=response.data }) }, getChildrens(tree, treeNode, resolve) { dict.dictList(tree.id).then(response => { resolve(response.data) }) }, } } </script> <style scoped> </style> The key method above is the getChildrens method, which calls the backend interface at each layer to query the child node data and add it to the table data in the tree structure. The tool js file dict.js that calls the backend structure import request from '@/utils/request' export default { //Data dictionary list dictList(id){ return request({ url: `/admin/cmn/dict/findChildData/${id}`, method: 'get' }) }, } 3.2 Implementation EffectThere are no problems with the front-end and back-end tests. Since lazy loading is used, the data of the child node will only be loaded when the parent node is clicked, avoiding system freezes due to excessive data volume. This is the end of this article about Vue elementUI's implementation of tree structure tables and lazy loading. For more related Vue elementUI content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: What are the new CSS :where and :is pseudo-class functions?
>>: HTML page adaptive width table
This article shares with you a js special effect ...
Table of contents Requirements encountered in act...
You must have inspiration to design a website. Goo...
Table of contents 1. The default focus is on the ...
This is not actually an official document of IE. I...
This article example shares the specific code of ...
IIS7 needs to confirm whether the "URL REWRI...
This article mainly introduces the implementation...
This article shares the specific code of the pull...
We will install phpMyAdmin to work with Apache on...
Recently, the client of a project insisted on hav...
Table of contents Server Planning 1. Install syst...
Preface These principles are summarized from actu...
Table of contents 1. World Map 1. Install openlay...
Preface Nowadays, in projects, the Axios library ...