2018-07-11 09:51:20 +00:00
|
|
|
<cn>
|
|
|
|
#### 从数据直接生成
|
|
|
|
使用 `treeData` 把 JSON 数据直接生成树结构。
|
|
|
|
</cn>
|
|
|
|
|
|
|
|
<us>
|
|
|
|
#### Generate form tree data
|
|
|
|
The tree structure can be populated using `treeData` property. This is a quick and easy way to provide the tree content.
|
|
|
|
</us>
|
|
|
|
|
|
|
|
```html
|
|
|
|
<template>
|
|
|
|
<a-tree-select
|
|
|
|
style="width: 300px"
|
|
|
|
:dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
|
|
|
|
:treeData="treeData"
|
|
|
|
placeholder='Please select'
|
|
|
|
treeDefaultExpandAll
|
|
|
|
v-model="value"
|
|
|
|
>
|
2018-12-25 04:00:39 +00:00
|
|
|
<span style="color: #08c" slot="title" slot-scope="{key, value}" v-if="key='0-0-1'">
|
2019-02-23 10:53:02 +00:00
|
|
|
Child Node1 {{value}}
|
2018-07-11 09:51:20 +00:00
|
|
|
</span>
|
|
|
|
</a-tree-select>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
const treeData = [{
|
2018-12-25 04:00:39 +00:00
|
|
|
title: 'Node1',
|
2018-07-11 09:51:20 +00:00
|
|
|
value: '0-0',
|
|
|
|
key: '0-0',
|
|
|
|
children: [{
|
|
|
|
value: '0-0-1',
|
|
|
|
key: '0-0-1',
|
2018-12-25 04:00:39 +00:00
|
|
|
scopedSlots: { // custom title
|
|
|
|
title: 'title',
|
2018-07-11 09:51:20 +00:00
|
|
|
},
|
|
|
|
}, {
|
2018-12-25 04:00:39 +00:00
|
|
|
title: 'Child Node2',
|
2018-07-11 09:51:20 +00:00
|
|
|
value: '0-0-2',
|
|
|
|
key: '0-0-2',
|
|
|
|
}],
|
|
|
|
}, {
|
2018-12-25 04:00:39 +00:00
|
|
|
title: 'Node2',
|
2018-07-11 09:51:20 +00:00
|
|
|
value: '0-1',
|
|
|
|
key: '0-1',
|
|
|
|
}]
|
|
|
|
export default {
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
value: undefined,
|
|
|
|
treeData,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
value (value) {
|
|
|
|
console.log(value)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
```
|