naive-ui/demo/documentation/components/tree/zhCN/basic.demo.md
07akioni 487001d697 build: add changelog to site, refactor loader based on suffix
.demo.md for component demo
.demo-entry.md for demo entry
.md for common docs
2020-08-19 23:30:04 +08:00

41 lines
810 B
Markdown

# 基础用法
好在这颗树不是活的,也不平衡。
```html
<n-tree
block-node
:data="data"
:default-expanded-keys="defaultExpandedKeys"
/>
```
```js
function createData (level = 4, baseKey = '') {
if (!level) return undefined
return Array
.apply(null, { length: 6 - level })
.map((_, index) => {
const key = '' + baseKey + level + index
return {
label: createLabel(level),
key,
children: createData(level - 1, key)
}
})
}
function createLabel (level) {
if (level === 4) return '道生一'
if (level === 3) return '一生二'
if (level === 2) return '二生三'
if (level === 1) return '三生万物'
}
export default {
data () {
return {
data: createData(),
defaultExpandedKeys: ['40', '41']
}
}
}
```