Skip to content

Commit eb94175

Browse files
committed
update README.md
1 parent 7ab1587 commit eb94175

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

README.md

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
> A simple tree component for vue.js
44
5-
**v2.2.0优化核心计算方法,添加 `label` 可控制选择框样式**
5+
**v2.2.0优化核心计算方法,添加 `label` 可定制选择框样式**
66

77
## 介绍
88

@@ -41,16 +41,17 @@ npm install vue-simple-tree --sve-dev
4141

4242
`treeData`
4343

44-
> `id`必要属性,`Number`
44+
- `id` 必要属性,类型 `Number`
4545

46-
> `name`必要属性,`String`,可自定义,默认`name`,如`options.itemName:'display_name'`
46+
- `name` 必要属性,类型 `String`可自定义,默认 `name`,如: `options.itemName:'label'`
4747

48-
> `children`非必要,`Array`
48+
- `children` 非必要,类型 `Array`
4949

50-
treeData示例
50+
### treeData示例
51+
./tree.json
5152
```json
5253
{
53-
"data": [{
54+
"data": [{
5455
"id": "1",
5556
"name": "Root",
5657
"children": [
@@ -81,20 +82,24 @@ treeData示例
8182

8283
有两种使用方法:
8384

84-
1. 局部注册component(推荐)
85+
1. 局部注册
8586

8687
`App.vue`
8788

8889
```vue
8990
<template>
9091
<div id="app">
91-
<vue-tree v-model="checkedIds" :tree-data="treeData" :options="options"></vue-tree>
92+
<vue-tree
93+
v-model="checkedIds"
94+
:tree-data="treeData"
95+
:options="options"
96+
/>
9297
</div>
9398
</template>
9499
95100
<script>
96101
import VueTree from 'vue-simple-tree/src/components/VueTree.vue'
97-
import Tree from 'tree.json'
102+
import Tree from './tree.json'
98103
99104
export default {
100105
name: 'app',
@@ -112,7 +117,7 @@ treeData示例
112117
}
113118
</script>
114119
```
115-
2. 全局注册,通过插件形式注册全局component
120+
2. 通过插件形式全局注册
116121
117122
`main.js`
118123
@@ -134,12 +139,16 @@ treeData示例
134139
```vue
135140
<template>
136141
<div id="app">
137-
<vue-tree v-model="checkedIds" :tree-data="treeData" :options="options"></vue-tree>
142+
<vue-tree
143+
v-model="checkedIds"
144+
:tree-data="treeData"
145+
:options="options"
146+
/>
138147
</div>
139148
</template>
140149
141150
<script>
142-
import Tree from 'tree.json';
151+
import Tree from './tree.json';
143152
export default {
144153
name: 'app',
145154
data () {
@@ -157,7 +166,7 @@ treeData示例
157166
158167
以下是默认设置.
159168
160-
你可以在`options`里覆盖默认设置,或仅设置若干项`options: {someOption: true}`
169+
你可以在`options`里覆盖默认设置,或仅设置若干项`options: {someOption: optionValue}`
161170
162171
你也可以绑定一个空的对象`:options="{}"`或直接忽略`options`
163172
@@ -172,9 +181,6 @@ options: {
172181
// Boolean,是否显示选择框
173182
checkbox: true,
174183

175-
// Array,初始化时选中id (v2.1以后不推荐使用,v3.0将废弃),替代方法见'#使用示例'章节
176-
checkedIds: [],
177-
178184
// Boolean,选中时是否展开节点
179185
checkedOpen: true,
180186

@@ -202,31 +208,30 @@ options: {
202208
// String,删除按钮(默认依赖font-awesome)
203209
deleteClass: 'fa fa-trash-o'
204210

205-
// Boolean,获取复选项目是否包含目录,默认`true`,如果只获取叶子节点设置为`false`
206-
idsWithParent: true
211+
// Boolean,v-model数据是否包含目录,默认`false`,如果只获取叶子节点设置为`false`
212+
idsWithParent: false
207213

208214
// Number,初始化时展开层级,根节点为0,默认0
209215
depthOpen: 0
210216

211-
// (v2.2新增), 选择框选中样式
217+
// (v2.2新增), 选择框label选中样式
212218
checkedClass: 'fa fa-check-square-o fa-fw'
213219

214-
// (v2.2新增), 选择框半选中样式
220+
// (v2.2新增), 选择框label半选中样式
215221
halfCheckedClass: 'fa fa-minus-square-o fa-fw'
216222

217-
// (v2.2新增), 选择框未选中样式
223+
// (v2.2新增), 选择框label未选中样式
218224
CheckedClass: 'fa fa-square-o fa-fw'
219225
}
220226
```
221-
> 注意:默认设置使用了`font-awesome`的图标
222-
如果你继续使用默认设置,请引入这个`css`库
227+
> 注意:默认设置使用了 [font-awesome](http://fontawesome.io/) 图标
228+
如果你继续使用默认设置,请确保这些图标能正常使用。
223229
224-
## 如何获取复选数据?
225-
226-
自v2.1起,不再从options.checkedIds获取复选数据,
227-
而是使用`v-model="checkedIds"`获取复选id.
230+
## 如何获取选择框数据?
228231
229-
> 默认情况下获取的ids是包含所有上级目录的,如果你想获取只包含叶子节点的ids,设置`options.idsWithParent`为`false`
232+
使用 `v-model="ids"` 获取选择框数据( `ids` 是一个只包含 `id` 的数组)
233+
234+
默认情况下 `ids` 只包含叶子节点(所有目录被过滤掉),如果你想获取包含上级目录的 `ids`,设置 `options.idsWithParent` 为 `true`
230235
231236
## 事件
232237

0 commit comments

Comments
 (0)