將一組內(nèi)容放置在多個折疊面板中,點擊面板的標(biāo)題可以展開或收縮其內(nèi)容。
import Vue from 'vue';
import { Collapse, CollapseItem } from 'vant';
Vue.use(Collapse);
Vue.use(CollapseItem);
通過 v-model
控制展開的面板列表,activeNames
為數(shù)組格式。
<van-collapse v-model="activeNames">
<van-collapse-item title="標(biāo)題1" name="1">內(nèi)容</van-collapse-item>
<van-collapse-item title="標(biāo)題2" name="2">內(nèi)容</van-collapse-item>
<van-collapse-item title="標(biāo)題3" name="3">內(nèi)容</van-collapse-item>
</van-collapse>
export default {
data() {
return {
activeNames: ['1'],
};
},
};
通過 accordion
可以設(shè)置為手風(fēng)琴模式,最多展開一個面板,此時 activeName
為字符串格式。
<van-collapse v-model="activeName" accordion>
<van-collapse-item title="標(biāo)題1" name="1">內(nèi)容</van-collapse-item>
<van-collapse-item title="標(biāo)題2" name="2">內(nèi)容</van-collapse-item>
<van-collapse-item title="標(biāo)題3" name="3">內(nèi)容</van-collapse-item>
</van-collapse>
export default {
data() {
return {
activeName: '1',
};
},
};
通過 disabled
屬性來禁用單個面板。
<van-collapse v-model="activeNames">
<van-collapse-item title="標(biāo)題1" name="1">內(nèi)容</van-collapse-item>
<van-collapse-item title="標(biāo)題2" name="2" disabled>內(nèi)容</van-collapse-item>
<van-collapse-item title="標(biāo)題3" name="3" disabled>內(nèi)容</van-collapse-item>
</van-collapse>
通過 title
插槽可以自定義標(biāo)題欄的內(nèi)容。
<van-collapse v-model="activeNames">
<van-collapse-item name="1">
<template #title>
<div>標(biāo)題1 <van-icon name="question-o" /></div>
</template>
內(nèi)容
</van-collapse-item>
<van-collapse-item title="標(biāo)題2" name="2" icon="shop-o">
內(nèi)容
</van-collapse-item>
</van-collapse>
export default {
data() {
return {
activeNames: ['1'],
};
},
};
參數(shù) | 說明 | 類型 | 默認(rèn)值 |
---|---|---|---|
v-model | 當(dāng)前展開面板的 name | 手風(fēng)琴模式:number | string
非手風(fēng)琴模式:(number | string)[] |
- |
accordion | 是否開啟手風(fēng)琴模式 | boolean | false
|
border | 是否顯示外邊框 | boolean | true
|
事件名 | 說明 | 回調(diào)參數(shù) |
---|---|---|
change | 切換面板時觸發(fā) | activeNames: 類型與 v-model 綁定的值一致 |
參數(shù) | 說明 | 類型 | 默認(rèn)值 |
---|---|---|---|
name | 唯一標(biāo)識符,默認(rèn)為索引值 | number | string | index
|
icon | 標(biāo)題欄左側(cè)圖標(biāo)名稱或圖片鏈接 | string | - |
size | 標(biāo)題欄大小,可選值為 large
|
string | - |
title | 標(biāo)題欄左側(cè)內(nèi)容 | number | string | - |
value | 標(biāo)題欄右側(cè)內(nèi)容 | number | string | - |
label | 標(biāo)題欄描述信息 | number | string | - |
border | 是否顯示內(nèi)邊框 | boolean | true
|
is-link | 是否展示標(biāo)題欄右側(cè)箭頭并開啟點擊反饋 | boolean | true
|
disabled | 是否禁用面板 | boolean | false
|
lazy-render v2.12.43
|
是否在首次展開時才渲染面板內(nèi)容 | boolean | true
|
title-class | 左側(cè)標(biāo)題額外類名 | string | - |
value-class | 右側(cè)內(nèi)容額外類名 | string | - |
label-class | 描述信息額外類名 | string | - |
名稱 | 說明 |
---|---|
default | 面板內(nèi)容 |
value | 自定義顯示內(nèi)容 |
icon | 自定義 icon
|
title | 自定義 title
|
right-icon | 自定義右側(cè)按鈕,默認(rèn)是 arrow
|
通過 ref 可以獲取到 CollapseItem 實例并調(diào)用實例方法,詳見組件實例方法。
方法名 | 說明 | 參數(shù) | 返回值 |
---|---|---|---|
toggle v2.10.9
|
切換面試展開狀態(tài),傳 true 為展開,false 為收起,不傳參為切換 |
expand?: boolean | - |
組件提供了下列 Less 變量,可用于自定義樣式,使用方法請參考主題定制。
名稱 | 默認(rèn)值 | 描述 |
---|---|---|
@collapse-item-transition-duration | @animation-duration-base
|
- |
@collapse-item-content-padding | @padding-sm @padding-md
|
- |
@collapse-item-content-font-size | @font-size-md
|
- |
@collapse-item-content-line-height | 1.5
|
- |
@collapse-item-content-text-color | @gray-6
|
- |
@collapse-item-content-background-color | @white
|
- |
@collapse-item-title-disabled-color | @gray-5
|
- |
更多建議: