Commit da76a837e32954c541111fc9dcca339616ac5726
1 parent
b31aab71
fix dom rendering problems
Showing
3 changed files
with
28 additions
and
22 deletions
Show diff stats
examples/routers/tree.vue
| @@ -34,11 +34,11 @@ | @@ -34,11 +34,11 @@ | ||
| 34 | size: 'small' | 34 | size: 'small' |
| 35 | }, | 35 | }, |
| 36 | on: { | 36 | on: { |
| 37 | - click: () => { | ||
| 38 | - this.cc(); | 37 | + click: ({target}) => { |
| 38 | + this.logger(target.textContent); | ||
| 39 | } | 39 | } |
| 40 | } | 40 | } |
| 41 | - }, '我是按钮') | 41 | + }, 'I\'m a button!'); |
| 42 | } | 42 | } |
| 43 | } | 43 | } |
| 44 | ] | 44 | ] |
| @@ -46,7 +46,7 @@ | @@ -46,7 +46,7 @@ | ||
| 46 | ] | 46 | ] |
| 47 | } | 47 | } |
| 48 | ] | 48 | ] |
| 49 | - } | 49 | + }; |
| 50 | }, | 50 | }, |
| 51 | methods: { | 51 | methods: { |
| 52 | handleAdd () { | 52 | handleAdd () { |
| @@ -55,18 +55,20 @@ | @@ -55,18 +55,20 @@ | ||
| 55 | title: 'test name', | 55 | title: 'test name', |
| 56 | checked: true | 56 | checked: true |
| 57 | } | 57 | } |
| 58 | - ) | 58 | + ); |
| 59 | }, | 59 | }, |
| 60 | handleUpdate () { | 60 | handleUpdate () { |
| 61 | - this.$set(this.baseData[0].children[0].children[1], 'checked', true); | 61 | + const child = this.baseData[0].children[0].children[1]; |
| 62 | + // console.log(JSON.stringify(this.baseData), '\n', JSON.stringify(child)); | ||
| 63 | + if (!child) return this.$Message.error('Node is async and is not loaded yet'); | ||
| 64 | + else this.$set(child, 'checked', true); | ||
| 62 | }, | 65 | }, |
| 63 | - cc () { | ||
| 64 | - console.log(99) | 66 | + logger (txt) { |
| 67 | + console.log(txt); | ||
| 65 | }, | 68 | }, |
| 66 | loadData (item, callback) { | 69 | loadData (item, callback) { |
| 67 | - item.loading = true; | ||
| 68 | setTimeout(() => { | 70 | setTimeout(() => { |
| 69 | - item.children = [ | 71 | + callback([ |
| 70 | { | 72 | { |
| 71 | title: 'children-1', | 73 | title: 'children-1', |
| 72 | loading: false, | 74 | loading: false, |
| @@ -77,11 +79,9 @@ | @@ -77,11 +79,9 @@ | ||
| 77 | loading: false, | 79 | loading: false, |
| 78 | children: [] | 80 | children: [] |
| 79 | } | 81 | } |
| 80 | - ]; | ||
| 81 | - item.loading = false; | ||
| 82 | - callback(); | 82 | + ]); |
| 83 | }, 2000); | 83 | }, 2000); |
| 84 | } | 84 | } |
| 85 | } | 85 | } |
| 86 | - } | 86 | + }; |
| 87 | </script> | 87 | </script> |
src/components/tree/node.vue
| @@ -16,8 +16,8 @@ | @@ -16,8 +16,8 @@ | ||
| 16 | <span v-else :class="titleClasses" v-html="data.title" @click="handleSelect"></span> | 16 | <span v-else :class="titleClasses" v-html="data.title" @click="handleSelect"></span> |
| 17 | <Tree-node | 17 | <Tree-node |
| 18 | v-if="data.expand" | 18 | v-if="data.expand" |
| 19 | - v-for="item in data.children" | ||
| 20 | - :key="item.nodeKey" | 19 | + v-for="(item, i) in data.children" |
| 20 | + :key="i" | ||
| 21 | :data="item" | 21 | :data="item" |
| 22 | :multiple="multiple" | 22 | :multiple="multiple" |
| 23 | :show-checkbox="showCheckbox"> | 23 | :show-checkbox="showCheckbox"> |
| @@ -61,6 +61,9 @@ | @@ -61,6 +61,9 @@ | ||
| 61 | prefixCls: prefixCls | 61 | prefixCls: prefixCls |
| 62 | }; | 62 | }; |
| 63 | }, | 63 | }, |
| 64 | + watch: { | ||
| 65 | + | ||
| 66 | + }, | ||
| 64 | computed: { | 67 | computed: { |
| 65 | classes () { | 68 | classes () { |
| 66 | return [ | 69 | return [ |
| @@ -104,12 +107,15 @@ | @@ -104,12 +107,15 @@ | ||
| 104 | if (item.disabled) return; | 107 | if (item.disabled) return; |
| 105 | 108 | ||
| 106 | // async loading | 109 | // async loading |
| 107 | - if (item.loading !== undefined && !item.children.length) { | 110 | + if (item.children.length === 0) { |
| 108 | const tree = findComponentUpward(this, 'Tree'); | 111 | const tree = findComponentUpward(this, 'Tree'); |
| 109 | if (tree && tree.loadData) { | 112 | if (tree && tree.loadData) { |
| 110 | - tree.loadData(item, () => { | ||
| 111 | - if (item.children.length) { | ||
| 112 | - this.handleExpand(item); | 113 | + this.$set(this.data, 'loading', true); |
| 114 | + tree.loadData(item, children => { | ||
| 115 | + this.$set(this.data, 'loading', false); | ||
| 116 | + if (children.length) { | ||
| 117 | + this.$set(this.data, 'children', children); | ||
| 118 | + this.$nextTick(() => this.handleExpand()); | ||
| 113 | } | 119 | } |
| 114 | }); | 120 | }); |
| 115 | return; | 121 | return; |
src/components/tree/tree.vue
| 1 | <template> | 1 | <template> |
| 2 | <div :class="prefixCls"> | 2 | <div :class="prefixCls"> |
| 3 | <Tree-node | 3 | <Tree-node |
| 4 | - v-for="item in stateTree" | ||
| 5 | - :key="item.nodeKey" | 4 | + v-for="(item, i) in stateTree" |
| 5 | + :key="i" | ||
| 6 | :data="item" | 6 | :data="item" |
| 7 | visible | 7 | visible |
| 8 | :multiple="multiple" | 8 | :multiple="multiple" |