TreeSelect 分类选择
单选模式
<van-tree-select
v-model:active-id="state.activeId"
v-model:main-active-index="state.activeIndex"
:items="items"
/>
import { reactive } from 'vue';
export default {
setup() {
const state = reactive({
activeId: 1,
activeIndex: 0,
});
const items = [
{
text: '浙江',
children: [
{ text: '杭州', id: 1 },
{ text: '温州', id: 2 },
],
},
{
text: '江苏',
children: [
{ text: '南京', id: 5 },
],
},
];
return {
state,
items,
};
},
};
多选模式
active-id
为数组格式时,可以选中多个右侧选项。
import { reactive } from 'vue';
setup() {
const state = reactive({
activeId: [1, 2],
activeIndex: 0,
});
const items = [
{
text: '浙江',
children: [
{ text: '杭州', id: 1 },
{ text: '温州', id: 2 },
],
},
{
text: '江苏',
children: [
{ text: '南京', id: 5 },
{ text: '无锡', id: 6 },
],
},
];
return {
state,
};
},
};
<van-tree-select
v-model:main-active-index="activeIndex"
height="55vw"
:items="items"
>
<template #content>
<van-image
v-if="activeIndex === 0"
src="https://img.yzcdn.cn/vant/apple-1.jpg"
/>
<van-image
v-if="activeIndex === 1"
/>
</template>
</van-tree-select>
徽标提示
设置 dot
属性后,会在图标右上角展示一个小红点;设置 badge
属性后,会在图标右上角展示相应的徽标。
<van-tree-select
v-model:main-active-index="activeIndex"
height="55vw"
:items="items"
/>
import { ref } from 'vue';
export default {
setup() {
const activeIndex = ref(0);
return {
activeIndex,
items: [
{ text: '浙江', children: [], dot: true },
{ text: '江苏', children: [], badge: 5 },
],
};
},
API
Props
Slots
Item 数据结构
组件提供了下列 Less 变量,可用于自定义样式,使用方法请参考主题定制。