2016-07-27 06:15:02 +00:00
|
|
|
<template>
|
2016-10-17 16:31:37 +00:00
|
|
|
<div class="el-tree" :class="{ 'el-tree--highlight-current': highlightCurrent }">
|
|
|
|
<el-tree-node
|
|
|
|
v-for="child in tree.root.childNodes"
|
|
|
|
:node="child"
|
|
|
|
:props="props"
|
|
|
|
:render-content="renderContent">
|
|
|
|
</el-tree-node>
|
2016-07-27 06:15:02 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script type="text/ecmascript-6">
|
|
|
|
import Tree from './model/tree';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'el-tree',
|
|
|
|
|
|
|
|
props: {
|
|
|
|
data: {
|
|
|
|
type: Array
|
|
|
|
},
|
2016-10-17 16:31:37 +00:00
|
|
|
renderContent: Function,
|
2016-07-27 06:15:02 +00:00
|
|
|
showCheckbox: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
default() {
|
|
|
|
return {
|
|
|
|
children: 'children',
|
|
|
|
label: 'label',
|
|
|
|
icon: 'icon'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
lazy: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
2016-10-17 16:31:37 +00:00
|
|
|
highlightCurrent: Boolean,
|
2016-07-27 06:15:02 +00:00
|
|
|
load: {
|
|
|
|
type: Function
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
|
|
|
this.$isTree = true;
|
|
|
|
|
|
|
|
this.tree = new Tree({
|
|
|
|
data: this.data,
|
|
|
|
lazy: this.lazy,
|
|
|
|
props: this.props,
|
|
|
|
load: this.load
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2016-10-17 16:31:37 +00:00
|
|
|
tree: {},
|
|
|
|
currentNode: null
|
2016-07-27 06:15:02 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
components: {
|
|
|
|
ElTreeNode: require('./tree-node.vue')
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
children: {
|
|
|
|
set(value) {
|
|
|
|
this.data = value;
|
|
|
|
},
|
|
|
|
get() {
|
|
|
|
return this.data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-10-08 05:58:31 +00:00
|
|
|
watch: {
|
|
|
|
data(newVal) {
|
|
|
|
this.tree.root.setData(newVal);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-07-27 06:15:02 +00:00
|
|
|
methods: {
|
|
|
|
getCheckedNodes(leafOnly) {
|
|
|
|
return this.tree.getCheckedNodes(leafOnly);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|