2017-02-06 11:24:03 +08:00
|
|
|
<template>
|
2017-10-23 11:55:35 +08:00
|
|
|
<div>
|
2017-10-24 18:14:22 +08:00
|
|
|
<Tree :data="baseData" :load-data="loadData" show-checkbox multiple></Tree>
|
2017-10-23 11:55:35 +08:00
|
|
|
<Button @click="handleAdd">add</Button>
|
|
|
|
<Button @click="handleUpdate">update</Button>
|
|
|
|
</div>
|
2017-02-06 11:24:03 +08:00
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
export default {
|
2017-03-03 10:35:38 +08:00
|
|
|
data () {
|
2017-02-07 11:34:00 +08:00
|
|
|
return {
|
2017-10-23 11:55:35 +08:00
|
|
|
baseData: [
|
2017-03-24 20:50:13 +08:00
|
|
|
{
|
2017-10-23 11:55:35 +08:00
|
|
|
expand: true,
|
|
|
|
title: 'parent 1',
|
2017-04-27 13:56:58 +08:00
|
|
|
children: [
|
|
|
|
{
|
2017-10-23 11:55:35 +08:00
|
|
|
title: 'parent 1-0',
|
2017-10-24 18:14:22 +08:00
|
|
|
expand: false,
|
|
|
|
children: [],
|
|
|
|
loading: false
|
2017-04-27 13:56:58 +08:00
|
|
|
},
|
|
|
|
{
|
2017-10-23 11:55:35 +08:00
|
|
|
title: 'parent 1-1',
|
2017-10-24 16:20:09 +08:00
|
|
|
expand: true,
|
2017-10-23 11:55:35 +08:00
|
|
|
checked: true,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
title: '<span style="color: red">leaf</span>',
|
2017-10-24 16:20:09 +08:00
|
|
|
render: (h) => {
|
|
|
|
return h('Button', {
|
|
|
|
props: {
|
2017-10-24 16:48:28 +08:00
|
|
|
type: 'primary',
|
|
|
|
size: 'small'
|
2017-10-24 16:20:09 +08:00
|
|
|
},
|
|
|
|
on: {
|
2017-10-24 14:08:52 +02:00
|
|
|
click: ({target}) => {
|
|
|
|
this.logger(target.textContent);
|
2017-10-24 16:20:09 +08:00
|
|
|
}
|
|
|
|
}
|
2017-10-24 14:08:52 +02:00
|
|
|
}, 'I\'m a button!');
|
2017-10-24 16:20:09 +08:00
|
|
|
}
|
2017-10-23 11:55:35 +08:00
|
|
|
}
|
|
|
|
]
|
2017-04-27 13:56:58 +08:00
|
|
|
}
|
|
|
|
]
|
2017-03-27 14:28:42 +08:00
|
|
|
}
|
2017-03-24 20:50:13 +08:00
|
|
|
]
|
2017-10-24 14:08:52 +02:00
|
|
|
};
|
2017-03-03 11:35:33 +08:00
|
|
|
},
|
|
|
|
methods: {
|
2017-10-23 11:55:35 +08:00
|
|
|
handleAdd () {
|
|
|
|
this.baseData.push(
|
|
|
|
{
|
|
|
|
title: 'test name',
|
|
|
|
checked: true
|
|
|
|
}
|
2017-10-24 14:08:52 +02:00
|
|
|
);
|
2017-10-23 11:55:35 +08:00
|
|
|
},
|
|
|
|
handleUpdate () {
|
2017-10-24 14:08:52 +02:00
|
|
|
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);
|
2017-10-24 16:20:09 +08:00
|
|
|
},
|
2017-10-24 14:08:52 +02:00
|
|
|
logger (txt) {
|
|
|
|
console.log(txt);
|
2017-10-24 18:14:22 +08:00
|
|
|
},
|
|
|
|
loadData (item, callback) {
|
|
|
|
setTimeout(() => {
|
2017-10-24 14:08:52 +02:00
|
|
|
callback([
|
2017-10-24 18:14:22 +08:00
|
|
|
{
|
|
|
|
title: 'children-1',
|
|
|
|
loading: false,
|
|
|
|
children: []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'children-2',
|
|
|
|
loading: false,
|
|
|
|
children: []
|
|
|
|
}
|
2017-10-24 14:08:52 +02:00
|
|
|
]);
|
2017-10-24 18:14:22 +08:00
|
|
|
}, 2000);
|
2017-10-23 11:55:35 +08:00
|
|
|
}
|
2017-02-07 11:34:00 +08:00
|
|
|
}
|
2017-10-24 14:08:52 +02:00
|
|
|
};
|
2017-02-07 11:34:00 +08:00
|
|
|
</script>
|