vue+element树组件 实现树懒加载_忘却_前端开发者

 本文连接 https://www.cnblogs.com/aknife/p/11709255.html

https://www.cnblogs.com/aknife/p/11709255.html

一.页面样式

 

二.数据库

 

 三.前端页面代码

 1 <template>
 2 
 3   <el-tree :props="props"
 4            :load="loadNode"
 5            lazy
 6            show-checkbox>
 7   </el-tree>
 8 
 9 </template>
10 <script>
11 export default {
12   data () {
13     return {
14       props: {
15         label: 'name',
16         children: 'zones',
17         isLeaf: 'leaf',
18 
19       },
20     };
21   },
22   methods: {
23     loadNode (node, resolve) {
24       //如果展开第一级节点,从后台加载一级节点列表
25       if (node.level == 0) {
26         this.loadfirstnode(resolve);
27       }
28       //如果展开其他级节点,动态从后台加载下一级节点列表
29       if (node.level >= 1) {
30         this.loadchildnode(node, resolve);
31       }
32     },
33     //加载第一级节点
34     loadfirstnode (resolve) {
35 
36       this.api({
37         url: "/test/tree",
38         method: "post",
39 
40       }).then(data => {
41         console.log(data);
42         //this.data = data.list;
43         return resolve(data.list);
44 
45       })
46     },
55     //加载节点的子节点集合
56     loadchildnode (node, resolve) {
57       this.api({
58         url: "/test/tree2",
59         method: "post",
60         params: {
61           id: node.data.id
62         }
63       }).then(data => {
64         console.log(data);
65         //this.defaultProps.children = data.list;
66         return resolve(data.list);
67 
68       })
69     }
70 
71   }
72 
73 }
74 </script>
 1 <template>
 2 
 3   <el-tree :props="props"
 4            :load="loadNode"
 5            lazy
 6            show-checkbox>
 7   </el-tree>
 8 
 9 </template>
10 <script>
11 export default {
12   data () {
13     return {
14       props: {
15         label: 'name',
16         children: 'zones',
17         isLeaf: 'leaf',
18 
19       },
20     };
21   },
22   methods: {
23     loadNode (node, resolve) {
24       //如果展开第一级节点,从后台加载一级节点列表
25       if (node.level == 0) {
26         this.loadfirstnode(resolve);
27       }
28       //如果展开其他级节点,动态从后台加载下一级节点列表
29       if (node.level >= 1) {
30         this.loadchildnode(node, resolve);
31       }
32     },
33     //加载第一级节点
34     loadfirstnode (resolve) {
35 
36       this.api({
37         url: "/test/tree",
38         method: "post",
39 
40       }).then(data => {
41         console.log(data);
42         //this.data = data.list;
43         return resolve(data.list);
44 
45       })
46     },
55     //加载节点的子节点集合
56     loadchildnode (node, resolve) {
57       this.api({
58         url: "/test/tree2",
59         method: "post",
60         params: {
61           id: node.data.id
62         }
63       }).then(data => {
64         console.log(data);
65         //this.defaultProps.children = data.list;
66         return resolve(data.list);
67 
68       })
69     }
70 
71   }
72 
73 }
74 </script>

1<template> 2 3<el-tree :props=”props” 4 :load=”loadNode” 5 lazy
6 show-checkbox> 7</el-tree> 8 9</template>10<script>11export default {
12 data () {
13return {
14 props: {
15 label: name,
16 children: zones,
17 isLeaf: leaf,
1819 },
20 };
21 },
22 methods: {
23 loadNode (node, resolve) {
24//如果展开第一级节点,从后台加载一级节点列表25if (node.level ==0) {
26this.loadfirstnode(resolve);
27 }
28//如果展开其他级节点,动态从后台加载下一级节点列表29if (node.level >=1) {
30this.loadchildnode(node, resolve);
31 }
32 },
33//加载第一级节点34 loadfirstnode (resolve) {
3536this.api({
37 url: /test/tree,
38 method: post,
3940 }).then(data => {
41 console.log(data);
42//this.data = data.list;43return resolve(data.list);
4445 })
46 },
55//加载节点的子节点集合56 loadchildnode (node, resolve) {
57this.api({
58 url: /test/tree2,
59 method: post,
60 params: {
61 id: node.data.id
62 }
63 }).then(data => {
64 console.log(data);
65//this.defaultProps.children = data.list;66return resolve(data.list);
6768 })
69 }
7071 }
7273}
74</script>

 

 

controller层

    @PostMapping("/tree")
    public JSONObject tree( ) {return userService.tree();
    }

    @PostMapping("/tree2")
    public JSONObject tree(@RequestParam Map<String, Object> user) {return userService.tree2(user);
    }
    @PostMapping("/tree")
    public JSONObject tree( ) {return userService.tree();
    }

    @PostMapping("/tree2")
    public JSONObject tree(@RequestParam Map<String, Object> user) {return userService.tree2(user);
    }

)
public JSONObject tree( ) {return userService.tree(); }
)
public user) {return userService.tree2(user);

 

 

service层

    /**
     * 树
     */
    JSONObject tree();
    
    /**
     * 树
     */
    JSONObject tree2(Map<String, Object> user);
    /**
     * 树
     */
    JSONObject tree();
    
    /**
     * 树
     */
    JSONObject tree2(Map<String, Object> user);

/**
* 树
*/
JSONObject tree();

/**
* 树
*/
JSONObject tree2(Map

 

 

serviceImpl层

    @Override
    public JSONObject tree() {
        List<JSONObject> list=userDao.tree();
        System.out.println(list);
        return CommonUtil.successPage(list);
    }
    
    @Override
    public JSONObject tree2(Map<String, Object> user) {
        int codept=Integer.parseInt(user.get("id").toString()) ;
        List<JSONObject> list=userDao.tree2(codept);
        return CommonUtil.successPage(list);
    }
    @Override
    public JSONObject tree() {
        List<JSONObject> list=userDao.tree();
        System.out.println(list);
        return CommonUtil.successPage(list);
    }
    
    @Override
    public JSONObject tree2(Map<String, Object> user) {
        int codept=Integer.parseInt(user.get("id").toString()) ;
        List<JSONObject> list=userDao.tree2(codept);
        return CommonUtil.successPage(list);
    }

@Override
public JSONObject tree() {
List
userDao.tree();
System.out.println(list);
return CommonUtil.successPage(list);
}

@Override
public user) {
int).toString()) ;
List
userDao.tree2(codept);
return CommonUtil.successPage(list);
}

 

dao层

    /**
     * 树
     */
    List<JSONObject> tree();
    List<JSONObject> tree2(@Param("codept")int codept);
    /**
     * 树
     */
    List<JSONObject> tree();
    List<JSONObject> tree2(@Param("codept")int codept);

/**
* 树
*/
List
tree();
List
int

 

mapper层

    <select id="tree" resultType="com.alibaba.fastjson.JSONObject">
     SELECT [id]
      ,[codept]
      ,[name]
  FROM [dbo].[Dept] WHERE codept ='0'
    </select>
<select id="tree2" resultType="com.alibaba.fastjson.JSONObject"> SELECT [id] ,[codept] ,[name] FROM [dbo].[Dept] WHERE codept =#{codept} </select>
    <select id="tree" resultType="com.alibaba.fastjson.JSONObject">
     SELECT [id]
      ,[codept]
      ,[name]
  FROM [dbo].[Dept] WHERE codept ='0'
    </select>
<select id="tree2" resultType="com.alibaba.fastjson.JSONObject"> SELECT [id] ,[codept] ,[name] FROM [dbo].[Dept] WHERE codept =#{codept} </select>


SELECT [id]
,[codept]
,[name]
FROM [dbo].[Dept] WHERE codept


SELECT [id]
,[codept]
,[name]
FROM [dbo].[Dept] WHERE codept
#{codept}

 

 

本文连接https://www.cnblogs.com/aknife/p/11709255.html

https://www.cnblogs.com/aknife/p/11709255.html

 

» 本文来自:前端开发者 » 《vue+element树组件 实现树懒加载_忘却_前端开发者》
» 本文链接地址:https://www.rokub.com/73748.html
» 您也可以订阅本站:https://www.rokub.com
赞(0)
64K

评论 抢沙发

评论前必须登录!