單元格為列表中的單個展示項。
import Vue from 'vue';
import { Cell, CellGroup } from 'vant';
Vue.use(Cell);
Vue.use(CellGroup);
Cell 可以單獨使用,也可以與 CellGroup 搭配使用,CellGroup 可以為 Cell 提供上下外邊框。
<van-cell-group>
<van-cell title="單元格" value="內容" />
<van-cell title="單元格" value="內容" label="描述信息" />
</van-cell-group>
通過 CellGroup 的 inset 屬性,可以將單元格轉換為圓角卡片風格(從 2.12.25 版本開始支持)。
<van-cell-group inset>
<van-cell title="單元格" value="內容" />
<van-cell title="單元格" value="內容" label="描述信息" />
</van-cell-group>
通過 size 屬性可以控制單元格的大小。
<van-cell title="單元格" value="內容" size="large" />
<van-cell title="單元格" value="內容" size="large" label="描述信息" />
通過 icon 屬性在標題左側展示圖標。
<van-cell title="單元格" icon="location-o" />
只設置 value 時,內容會靠左對齊。
<van-cell value="內容" />
設置 is-link 屬性后會在單元格右側顯示箭頭,并且可以通過 arrow-direction 屬性控制箭頭方向。
<van-cell title="單元格" is-link />
<van-cell title="單元格" is-link value="內容" />
<van-cell title="單元格" is-link arrow-direction="down" value="內容" />
可以通過 url 屬性進行 URL 跳轉,或通過 to 屬性進行路由跳轉。
<van-cell title="URL 跳轉" is-link url="/vant/mobile.html" />
<van-cell title="路由跳轉" is-link to="index" />
通過 CellGroup 的 title 屬性可以指定分組標題。
<van-cell-group title="分組1">
<van-cell title="單元格" value="內容" />
</van-cell-group>
<van-cell-group title="分組2">
<van-cell title="單元格" value="內容" />
</van-cell-group>
如以上用法不能滿足你的需求,可以使用插槽來自定義內容。
<van-cell value="內容" is-link>
<!-- 使用 title 插槽來自定義標題 -->
<template #title>
<span class="custom-title">單元格</span>
<van-tag type="danger">標簽</van-tag>
</template>
</van-cell>
<van-cell title="單元格" icon="shop-o">
<!-- 使用 right-icon 插槽來自定義右側圖標 -->
<template #right-icon>
<van-icon name="search" class="search-icon" />
</template>
</van-cell>
<style>
.custom-title {
margin-right: 4px;
vertical-align: middle;
}
.search-icon {
font-size: 16px;
line-height: inherit;
}
</style>
通過 center 屬性可以讓 Cell 的左右內容都垂直居中。
<van-cell center title="單元格" value="內容" label="描述信息" />
參數(shù) | 說明 | 類型 | 默認值 |
---|---|---|---|
title | 分組標題 | string | -
|
border | 是否顯示外邊框 | boolean | true
|
參數(shù) | 說明 | 類型 | 默認值 |
---|---|---|---|
title | 左側標題 | number | string | - |
value | 右側內容 | number | string | - |
label | 標題下方的描述信息 | string | - |
size | 單元格大小,可選值為 large
|
string | - |
icon | 左側圖標名稱或圖片鏈接 | string | - |
icon-prefix v2.5.3
|
圖標類名前綴,同 Icon 組件的 class-prefix 屬性 | string | van-icon
|
url | 點擊后跳轉的鏈接地址 | string | - |
to | 點擊后跳轉的目標路由對象,同 vue-router 的 to 屬性 | string | object | - |
border | 是否顯示內邊框 | boolean | true
|
replace | 是否在跳轉時替換當前頁面歷史 | boolean | false
|
clickable | 是否開啟點擊反饋 | boolean | null
|
is-link | 是否展示右側箭頭并開啟點擊反饋 | boolean | false
|
required | 是否顯示表單必填星號 | boolean | false
|
center | 是否使內容垂直居中 | boolean | false
|
arrow-direction | 箭頭方向,可選值為 left up down
|
string | right
|
title-style | 左側標題額外樣式 | any | - |
title-class | 左側標題額外類名 | any | - |
value-class | 右側內容額外類名 | any | - |
label-class | 描述信息額外類名 | any | - |
事件名 | 說明 | 回調參數(shù) |
---|---|---|
click | 點擊單元格時觸發(fā) | event: Event |
名稱 | 說明 |
---|---|
default | 默認插槽 |
title | 自定義分組標題 |
名稱 | 說明 |
---|---|
default | 自定義右側 value 的內容 |
title | 自定義左側 title 的內容 |
label | 自定義標題下方 label 的內容 |
icon | 自定義左側圖標 |
right-icon | 自定義右側按鈕,默認為arrow
|
extra | 自定義單元格最右側的額外內容 |
組件提供了下列 Less 變量,可用于自定義樣式,使用方法請參考主題定制。
名稱 | 默認值 | 描述 |
---|---|---|
@cell-font-size | @font-size-md
|
- |
@cell-line-height | 24px
|
- |
@cell-vertical-padding | 10px
|
- |
@cell-horizontal-padding | @padding-md
|
- |
@cell-text-color | @text-color
|
- |
@cell-background-color | @white
|
- |
@cell-border-color | @border-color
|
- |
@cell-active-color | @active-color
|
- |
@cell-required-color | @red
|
- |
@cell-label-color | @gray-6
|
- |
@cell-label-font-size | @font-size-sm
|
- |
@cell-label-line-height | @line-height-sm
|
- |
@cell-label-margin-top | @padding-base
|
- |
@cell-value-color | @gray-6
|
- |
@cell-icon-size | 16px
|
- |
@cell-right-icon-color | @gray-6
|
- |
@cell-large-vertical-padding | @padding-sm
|
- |
@cell-large-title-font-size | @font-size-lg
|
- |
@cell-large-label-font-size | @font-size-md
|
- |
@cell-group-background-color | @white
|
- |
@cell-group-title-color | @gray-6
|
- |
@cell-group-title-padding | @padding-md @padding-md @padding-xs
|
- |
@cell-group-title-font-size | @font-size-md
|
- |
@cell-group-title-line-height | 16px
|
- |
更多建議: