Blame view

examples/routers/tree.vue 3.07 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
37
38
39
40
41
42
                                                  },
                                                  on: {
                                                      click: () => {
                                                          this.cc();
                                                      }
                                                  }
                                              }, '我是按钮')
                                          }
6ed0cd73   梁灏   update Tree demo
43
44
                                      }
                                  ]
69a10b78   梁灏   fixed #787
45
46
                              }
                          ]
c8157442   梁灏   fixed #499
47
                      }
75c32d5f   梁灏   rebuild Tree
48
                  ]
e81207a2   梁灏   update Tree
49
              }
9d79a51f   梁灏   update Tree
50
51
          },
          methods: {
6ed0cd73   梁灏   update Tree demo
52
53
54
55
56
57
58
59
60
              handleAdd () {
                  this.baseData.push(
                      {
                          title: 'test name',
                          checked: true
                      }
                  )
              },
              handleUpdate () {
9b24f1ab   梁灏   Tree add Render f...
61
62
63
64
                  this.$set(this.baseData[0].children[0].children[1], 'checked', true);
              },
              cc () {
                  console.log(99)
b31aab71   梁灏   Tree add async lo...
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
              },
              loadData (item, callback) {
                  item.loading = true;
                  setTimeout(() => {
                      item.children = [
                          {
                              title: 'children-1',
                              loading: false,
                              children: []
                          },
                          {
                              title: 'children-2',
                              loading: false,
                              children: []
                          }
                      ];
                      item.loading = false;
                      callback();
                  }, 2000);
6ed0cd73   梁灏   update Tree demo
84
              }
e81207a2   梁灏   update Tree
85
86
87
          }
      }
  </script>