diff --git a/examples/routers/tree.vue b/examples/routers/tree.vue
index 6bbc059..721a9c3 100644
--- a/examples/routers/tree.vue
+++ b/examples/routers/tree.vue
@@ -34,11 +34,11 @@
size: 'small'
},
on: {
- click: () => {
- this.cc();
+ click: ({target}) => {
+ this.logger(target.textContent);
}
}
- }, '我是按钮')
+ }, 'I\'m a button!');
}
}
]
@@ -46,7 +46,7 @@
]
}
]
- }
+ };
},
methods: {
handleAdd () {
@@ -55,18 +55,20 @@
title: 'test name',
checked: true
}
- )
+ );
},
handleUpdate () {
- this.$set(this.baseData[0].children[0].children[1], 'checked', true);
+ 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);
},
- cc () {
- console.log(99)
+ logger (txt) {
+ console.log(txt);
},
loadData (item, callback) {
- item.loading = true;
setTimeout(() => {
- item.children = [
+ callback([
{
title: 'children-1',
loading: false,
@@ -77,11 +79,9 @@
loading: false,
children: []
}
- ];
- item.loading = false;
- callback();
+ ]);
}, 2000);
}
}
- }
+ };
diff --git a/src/components/tree/node.vue b/src/components/tree/node.vue
index 8a7e789..6935dcb 100644
--- a/src/components/tree/node.vue
+++ b/src/components/tree/node.vue
@@ -16,8 +16,8 @@
@@ -61,6 +61,9 @@
prefixCls: prefixCls
};
},
+ watch: {
+
+ },
computed: {
classes () {
return [
@@ -104,12 +107,15 @@
if (item.disabled) return;
// async loading
- if (item.loading !== undefined && !item.children.length) {
+ if (item.children.length === 0) {
const tree = findComponentUpward(this, 'Tree');
if (tree && tree.loadData) {
- tree.loadData(item, () => {
- if (item.children.length) {
- this.handleExpand(item);
+ this.$set(this.data, 'loading', true);
+ tree.loadData(item, children => {
+ this.$set(this.data, 'loading', false);
+ if (children.length) {
+ this.$set(this.data, 'children', children);
+ this.$nextTick(() => this.handleExpand());
}
});
return;
diff --git a/src/components/tree/tree.vue b/src/components/tree/tree.vue
index 6662131..603885f 100644
--- a/src/components/tree/tree.vue
+++ b/src/components/tree/tree.vue
@@ -1,8 +1,8 @@