Blame view

examples/routers/tree.vue 3.22 KB
89f2ba8b   梁灏   init Tree component
1
  <template>
6ed0cd73   梁灏   update Tree demo
2
      <div>
b31aab71   梁灏   Tree add async lo...
3
          <Tree :data="baseData" :load-data="loadData" show-checkbox multiple></Tree>
6ed0cd73   梁灏   update Tree demo
4
5
6
          <Button @click="handleAdd">add</Button>
          <Button @click="handleUpdate">update</Button>
      </div>
89f2ba8b   梁灏   init Tree component
7
8
9
  </template>
  <script>
      export default {
e6c0b158   梁灏   update
10
          data () {
e81207a2   梁灏   update Tree
11
              return {
6ed0cd73   梁灏   update Tree demo
12
                  baseData: [
75c32d5f   梁灏   rebuild Tree
13
                      {
6ed0cd73   梁灏   update Tree demo
14
15
                          expand: true,
                          title: 'parent 1',
69a10b78   梁灏   fixed #787
16
17
                          children: [
                              {
6ed0cd73   梁灏   update Tree demo
18
                                  title: 'parent 1-0',
b31aab71   梁灏   Tree add async lo...
19
20
21
                                  expand: false,
                                  children: [],
                                  loading: false
69a10b78   梁灏   fixed #787
22
23
                              },
                              {
6ed0cd73   梁灏   update Tree demo
24
                                  title: 'parent 1-1',
9b24f1ab   梁灏   Tree add Render f...
25
                                  expand: true,
6ed0cd73   梁灏   update Tree demo
26
27
28
29
                                  checked: true,
                                  children: [
                                      {
                                          title: '<span style="color: red">leaf</span>',
9b24f1ab   梁灏   Tree add Render f...
30
31
32
                                          render: (h) => {
                                              return h('Button', {
                                                  props: {
76a47814   梁灏   fixed #2128
33
34
                                                      type: 'primary',
                                                      size: 'small'
9b24f1ab   梁灏   Tree add Render f...
35
36
                                                  },
                                                  on: {
da76a837   Sergio Crisostomo   fix dom rendering...
37
38
                                                      click: ({target}) => {
                                                          this.logger(target.textContent);
9b24f1ab   梁灏   Tree add Render f...
39
40
                                                      }
                                                  }
da76a837   Sergio Crisostomo   fix dom rendering...
41
                                              }, 'I\'m a button!');
9b24f1ab   梁灏   Tree add Render f...
42
                                          }
6ed0cd73   梁灏   update Tree demo
43
44
                                      }
                                  ]
69a10b78   梁灏   fixed #787
45
46
                              }
                          ]
c8157442   梁灏   fixed #499
47
                      }
75c32d5f   梁灏   rebuild Tree
48
                  ]
da76a837   Sergio Crisostomo   fix dom rendering...
49
              };
9d79a51f   梁灏   update Tree
50
51
          },
          methods: {
6ed0cd73   梁灏   update Tree demo
52
53
54
55
56
57
              handleAdd () {
                  this.baseData.push(
                      {
                          title: 'test name',
                          checked: true
                      }
da76a837   Sergio Crisostomo   fix dom rendering...
58
                  );
6ed0cd73   梁灏   update Tree demo
59
60
              },
              handleUpdate () {
da76a837   Sergio Crisostomo   fix dom rendering...
61
62
63
64
                  const child = this.baseData[0].children[0].children[1];
                //  console.log(JSON.stringify(this.baseData), '\n', JSON.stringify(child));
                  if (!child) return this.$Message.error('Node is async and is not loaded yet');
                  else this.$set(child, 'checked', true);
9b24f1ab   梁灏   Tree add Render f...
65
              },
da76a837   Sergio Crisostomo   fix dom rendering...
66
67
              logger (txt) {
                  console.log(txt);
b31aab71   梁灏   Tree add async lo...
68
69
              },
              loadData (item, callback) {
b31aab71   梁灏   Tree add async lo...
70
                  setTimeout(() => {
da76a837   Sergio Crisostomo   fix dom rendering...
71
                      callback([
b31aab71   梁灏   Tree add async lo...
72
73
74
75
76
77
78
79
80
81
                          {
                              title: 'children-1',
                              loading: false,
                              children: []
                          },
                          {
                              title: 'children-2',
                              loading: false,
                              children: []
                          }
da76a837   Sergio Crisostomo   fix dom rendering...
82
                      ]);
b31aab71   梁灏   Tree add async lo...
83
                  }, 2000);
6ed0cd73   梁灏   update Tree demo
84
              }
e81207a2   梁灏   update Tree
85
          }
da76a837   Sergio Crisostomo   fix dom rendering...
86
      };
e81207a2   梁灏   update Tree
87
  </script>