Pārlūkot izejas kodu

feat:add tree demo

Pan 7 gadi atpakaļ
vecāks
revīzija
37b6253e14

+ 1 - 1
src/components/Breadcrumb/index.vue

@@ -24,7 +24,7 @@ export default {
24 24
       let matched = this.$route.matched.filter(item => item.name)
25 25
       const first = matched[0]
26 26
       if (first && first.name !== 'dashboard') {
27
-        matched = [{ path: '/dashboard', meta: { title: 'dashboard' }}].concat(matched)
27
+        matched = [{ path: '/dashboard', meta: { title: 'Dashboard' }}].concat(matched)
28 28
       }
29 29
       this.levelList = matched
30 30
     }

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1 - 0
src/icons/svg/tree.svg


+ 21 - 14
src/router/index.js

@@ -21,6 +21,7 @@ import Layout from '../views/layout/Layout'
21 21
 export const constantRouterMap = [
22 22
   { path: '/login', component: _import('login/index'), hidden: true },
23 23
   { path: '/404', component: _import('404'), hidden: true },
24
+
24 25
   {
25 26
     path: '/',
26 27
     component: Layout,
@@ -29,36 +30,42 @@ export const constantRouterMap = [
29 30
     hidden: true,
30 31
     children: [{
31 32
       path: 'dashboard',
32
-      component: _import('dashboard/index'),
33
-      meta: { title: 'dashboard', icon: 'dashboard' }
33
+      component: _import('dashboard/index')
34 34
     }]
35 35
   },
36 36
 
37 37
   {
38 38
     path: '/example',
39 39
     component: Layout,
40
-    redirect: 'noredirect',
40
+    redirect: '/example/table',
41 41
     name: 'Example',
42 42
     meta: { title: 'Example', icon: 'example' },
43 43
     children: [
44 44
       {
45
-        path: 'index',
46
-        name: 'Form',
47
-        component: _import('page/form'),
48
-        meta: { title: 'Form', icon: 'form' }
45
+        path: 'table',
46
+        name: 'Table',
47
+        component: _import('table/index'),
48
+        meta: { title: 'Table', icon: 'table' }
49
+      },
50
+      {
51
+        path: 'tree',
52
+        name: 'Tree',
53
+        component: _import('tree/index'),
54
+        meta: { title: 'Tree', icon: 'tree' }
49 55
       }
50 56
     ]
51 57
   },
52 58
 
53 59
   {
54
-    path: '/table',
60
+    path: '/form',
55 61
     component: Layout,
56
-    redirect: '/table/index',
57
-    children: [{
58
-      path: 'index',
59
-      name: 'Table',
60
-      component: _import('table/index'),
61
-      meta: { title: 'Table', icon: 'table' }}
62
+    children: [
63
+      {
64
+        path: 'index',
65
+        name: 'Form',
66
+        component: _import('form/index'),
67
+        meta: { title: 'Form', icon: 'form' }
68
+      }
62 69
     ]
63 70
   },
64 71
 

src/views/page/form.vue → src/views/form/index.vue


+ 71 - 0
src/views/tree/index.vue

@@ -0,0 +1,71 @@
1
+<template>
2
+  <div class="app-container">
3
+    <el-input placeholder="Filter keyword" v-model="filterText" style="margin-bottom:30px;"></el-input>
4
+
5
+    <el-tree class="filter-tree" :data="data2" :props="defaultProps" default-expand-all :filter-node-method="filterNode" ref="tree2"></el-tree>
6
+
7
+  </div>
8
+</template>
9
+
10
+<script>
11
+export default {
12
+  watch: {
13
+    filterText(val) {
14
+      this.$refs.tree2.filter(val)
15
+    }
16
+  },
17
+
18
+  methods: {
19
+    filterNode(value, data) {
20
+      if (!value) return true
21
+      return data.label.indexOf(value) !== -1
22
+    }
23
+  },
24
+
25
+  data() {
26
+    return {
27
+      filterText: '',
28
+      data2: [{
29
+        id: 1,
30
+        label: 'Level one 1',
31
+        children: [{
32
+          id: 4,
33
+          label: 'Level two 1-1',
34
+          children: [{
35
+            id: 9,
36
+            label: 'Level three 1-1-1'
37
+          }, {
38
+            id: 10,
39
+            label: 'Level three 1-1-2'
40
+          }]
41
+        }]
42
+      }, {
43
+        id: 2,
44
+        label: 'Level one 2',
45
+        children: [{
46
+          id: 5,
47
+          label: 'Level two 2-1'
48
+        }, {
49
+          id: 6,
50
+          label: 'Level two 2-2'
51
+        }]
52
+      }, {
53
+        id: 3,
54
+        label: 'Level one 3',
55
+        children: [{
56
+          id: 7,
57
+          label: 'Level two 3-1'
58
+        }, {
59
+          id: 8,
60
+          label: 'Level two 3-2'
61
+        }]
62
+      }],
63
+      defaultProps: {
64
+        children: 'children',
65
+        label: 'label'
66
+      }
67
+    }
68
+  }
69
+}
70
+</script>
71
+