W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
import Vue from 'vue';
import { TreeSelect } from 'vant';
Vue.use(TreeSelect);
item為分類顯示所需的數(shù)據(jù),數(shù)據(jù)格式見下方示例。main-active-index表示左側(cè)高亮選項的索引,active-id表示右側(cè)高亮選項的 id
<van-tree-select
:items="items"
:active-id.sync="activeId"
:main-active-index.sync="activeIndex"
/>
export default {
data() {
return {
items,
activeId: 1,
activeIndex: 0
};
}
}
active-id為數(shù)組格式時,可以選中多個右側(cè)選項
<van-tree-select
:items="items"
:active-id.sync="activeIds"
:main-active-index.sync="activeIndex"
/>
export default {
data() {
return {
items,
activeIds: [1, 2],
activeIndex: 0
};
}
}
通過content插槽可以自定義右側(cè)區(qū)域的內(nèi)容
<van-tree-select
height="55vw"
:items="items"
:main-active-index.sync="active"
>
<template slot="content">
<van-image v-if="active === 0" src="https://img.yzcdn.cn/vant/apple-1.jpg" rel="external nofollow" />
<van-image v-if="active === 1" src="https://img.yzcdn.cn/vant/apple-2.jpg" rel="external nofollow" />
</template>
</van-tree-select>
export default {
data() {
return {
active: 0,
items: [{ text: '分組 1' }, { text: '分組 2' }]
}
}
}
設(shè)置dot屬性后,會在圖標(biāo)右上角展示一個小紅點。設(shè)置info屬性后,會在圖標(biāo)右上角展示相應(yīng)的徽標(biāo)
<van-tree-select
height="55vw"
:items="items"
:main-active-index.sync="activeIndex"
/>
export default {
data() {
return {
activeIndex: 0,
items: [
{ text: '浙江', children: [], dot: true },
{ text: '江蘇', children: [], info: 5 }
]
}
}
}
參數(shù) | 說明 | 類型 | 默認(rèn)值 |
---|---|---|---|
items | 分類顯示所需的數(shù)據(jù) | Item[] | [] |
height | 高度,默認(rèn)單位為px | number | string | 300 |
main-active-index | 左側(cè)選中項的索引 | number | string | 0 |
active-id | 右側(cè)選中項的 id,支持傳入數(shù)組 | number | string | (number | string)[] | 0 |
max v2.2.0 | 右側(cè)項最大選中個數(shù) | number | string | Infinity |
事件名 | 說明 | 回調(diào)參數(shù) |
---|---|---|
click-nav | 點擊左側(cè)導(dǎo)航時觸發(fā) | index:被點擊的導(dǎo)航的索引 |
click-item | 點擊右側(cè)選擇項時觸發(fā) | data: 該點擊項的數(shù)據(jù) |
名稱 | 說明 |
---|---|
content | 自定義右側(cè)區(qū)域內(nèi)容 |
items 整體為一個數(shù)組,數(shù)組內(nèi)包含一系列描述分類的對象,每個分類里,text表示當(dāng)前分類的名稱,children表示分類里的可選項。
[
{
// 導(dǎo)航名稱
text: '所有城市',
// 導(dǎo)航名稱右上角徽標(biāo)
info: 3,
// 是否在導(dǎo)航名稱右上角顯示小紅點
dot: true,
// 導(dǎo)航節(jié)點額外類名
className: 'my-class',
// 該導(dǎo)航下所有的可選項
children: [
{
// 名稱
text: '溫州',
// id,作為匹配選中狀態(tài)的標(biāo)識符
id: 1,
// 禁用選項
disabled: true
},
{
text: '杭州',
id: 2
}
]
}
]
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: