mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-24 10:20:19 +08:00
[new feature] TreeSelect: main-active-index support sync modifier (#4132)
This commit is contained in:
parent
bfb3196438
commit
85356ac302
@ -91,7 +91,7 @@ export default {
|
|||||||
| items | Required datasets for the component | `Item[]` | `[]` |
|
| items | Required datasets for the component | `Item[]` | `[]` |
|
||||||
| height | Height | `string | number` | `300` |
|
| height | Height | `string | number` | `300` |
|
||||||
| main-Active-index | The index of selected parent node | `number` | `0` |
|
| main-Active-index | The index of selected parent node | `number` | `0` |
|
||||||
| active-id | Id of selected item | `string | number` | `0` |
|
| active-id | Id of selected item | `string | number | (string | number)[]` | `0` |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
|
@ -17,8 +17,7 @@ Vue.use(TreeSelect);
|
|||||||
<van-tree-select
|
<van-tree-select
|
||||||
:items="items"
|
:items="items"
|
||||||
:active-id="activeId"
|
:active-id="activeId"
|
||||||
:main-active-index="mainActiveIndex"
|
:main-active-index.sync="mainActiveIndex"
|
||||||
@click-nav="onClickNav"
|
|
||||||
@click-item="onClickItem"
|
@click-item="onClickItem"
|
||||||
/>
|
/>
|
||||||
```
|
```
|
||||||
@ -33,9 +32,6 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onClickNav(index) {
|
|
||||||
this.mainActiveIndex = index;
|
|
||||||
},
|
|
||||||
onClickItem(data) {
|
onClickItem(data) {
|
||||||
this.activeId = data.id;
|
this.activeId = data.id;
|
||||||
}
|
}
|
||||||
@ -49,8 +45,7 @@ export default {
|
|||||||
<van-tree-select
|
<van-tree-select
|
||||||
:items="items"
|
:items="items"
|
||||||
:active-id="activeIds"
|
:active-id="activeIds"
|
||||||
:main-active-index="mainActiveIndex"
|
:main-active-index.sync="mainActiveIndex"
|
||||||
@click-nav="onClickNav"
|
|
||||||
@click-item="onClickItem"
|
@click-item="onClickItem"
|
||||||
/>
|
/>
|
||||||
```
|
```
|
||||||
@ -65,9 +60,6 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onClickNav(index) {
|
|
||||||
this.mainActiveIndex = index;
|
|
||||||
},
|
|
||||||
onClickItem(data) {
|
onClickItem(data) {
|
||||||
const { id } = data;
|
const { id } = data;
|
||||||
const { activeIds } = this;
|
const { activeIds } = this;
|
||||||
@ -90,8 +82,8 @@ export default {
|
|||||||
|------|------|------|------|------|
|
|------|------|------|------|------|
|
||||||
| items | 分类显示所需的数据 | `Item[]` | `[]` | - |
|
| items | 分类显示所需的数据 | `Item[]` | `[]` | - |
|
||||||
| height | 高度,默认单位为 px | `string | number` | `300` | - |
|
| height | 高度,默认单位为 px | `string | number` | `300` | - |
|
||||||
| main-active-index | 左侧导航高亮的索引 | `number` | `0` | - |
|
| main-active-index | 左侧高亮选项的索引 | `number` | `0` | - |
|
||||||
| active-id | 右侧选择项,高亮的数据id | `string | number` | `0` | - |
|
| active-id | 右侧高亮选项的 id,支持传入数组 | `string | number | (string | number)[]` | `0` | - |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
|
@ -3,9 +3,8 @@
|
|||||||
<demo-block :title="$t('radioMode')">
|
<demo-block :title="$t('radioMode')">
|
||||||
<van-tree-select
|
<van-tree-select
|
||||||
:items="items"
|
:items="items"
|
||||||
:main-active-index="mainActiveIndex"
|
:main-active-index.sync="mainActiveIndex"
|
||||||
:active-id="activeId"
|
:active-id="activeId"
|
||||||
@navclick="onNavClick"
|
|
||||||
@itemclick="onItemClick"
|
@itemclick="onItemClick"
|
||||||
/>
|
/>
|
||||||
</demo-block>
|
</demo-block>
|
||||||
@ -13,9 +12,8 @@
|
|||||||
<demo-block :title="$t('multipleMode')">
|
<demo-block :title="$t('multipleMode')">
|
||||||
<van-tree-select
|
<van-tree-select
|
||||||
:items="items"
|
:items="items"
|
||||||
:main-active-index="mainActiveIndex2"
|
:main-active-index.sync="mainActiveIndex2"
|
||||||
:active-id="activeIds"
|
:active-id="activeIds"
|
||||||
@navclick="onNavClick2"
|
|
||||||
@itemclick="onItemClick2"
|
@itemclick="onItemClick2"
|
||||||
/>
|
/>
|
||||||
</demo-block>
|
</demo-block>
|
||||||
@ -140,18 +138,10 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
onNavClick(index) {
|
|
||||||
this.mainActiveIndex = index;
|
|
||||||
},
|
|
||||||
|
|
||||||
onItemClick(data) {
|
onItemClick(data) {
|
||||||
this.activeId = data.id;
|
this.activeId = data.id;
|
||||||
},
|
},
|
||||||
|
|
||||||
onNavClick2(index) {
|
|
||||||
this.mainActiveIndex2 = index;
|
|
||||||
},
|
|
||||||
|
|
||||||
onItemClick2(data) {
|
onItemClick2(data) {
|
||||||
const { id } = data;
|
const { id } = data;
|
||||||
const { activeIds } = this;
|
const { activeIds } = this;
|
||||||
|
@ -63,6 +63,7 @@ function TreeSelect(
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (!item.disabled) {
|
if (!item.disabled) {
|
||||||
emit(ctx, 'click-nav', index);
|
emit(ctx, 'click-nav', index);
|
||||||
|
emit(ctx, 'update:main-active-index', index);
|
||||||
|
|
||||||
// compatible for old usage, should be removed in next major version
|
// compatible for old usage, should be removed in next major version
|
||||||
emit(ctx, 'navclick', index);
|
emit(ctx, 'navclick', index);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user