fix dom rendering problems

This commit is contained in:
Sergio Crisostomo 2017-10-24 14:08:52 +02:00
parent b31aab71d2
commit da76a837e3
3 changed files with 28 additions and 22 deletions

View file

@ -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);
}
}
}
};
</script>

View file

@ -16,8 +16,8 @@
<span v-else :class="titleClasses" v-html="data.title" @click="handleSelect"></span>
<Tree-node
v-if="data.expand"
v-for="item in data.children"
:key="item.nodeKey"
v-for="(item, i) in data.children"
:key="i"
:data="item"
:multiple="multiple"
:show-checkbox="showCheckbox">
@ -60,6 +60,9 @@
return {
prefixCls: prefixCls
};
},
watch: {
},
computed: {
classes () {
@ -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;

View file

@ -1,8 +1,8 @@
<template>
<div :class="prefixCls">
<Tree-node
v-for="item in stateTree"
:key="item.nodeKey"
v-for="(item, i) in stateTree"
:key="i"
:data="item"
visible
:multiple="multiple"