Skip to content

参考

基于 Vant 4.x(v4.9.24+)的 API 速查——组件 props / events / slots / 命令式 API 签名 / Composables / TypeScript 类型 / CSS 变量入口。

组件分类速查表(80+ 组件)

基础组件(Basic)

标签中文名关键 Props
van-button按钮type / size / loading / icon / round / block / disabled / plain / hairline / square / color / url / to
van-cell单元格title / value / label / icon / is-link / to / center / size / clickable
van-cell-group单元格组title / inset / border
van-icon图标name / size / color / badge / class-prefix
van-image图片src / fit(contain/cover/fill/none/scale-down)/ width / height / lazy-load / round / show-error / show-loading
van-row / van-col栅格gutter / span / offset / justify / align
van-popup弹出层v-model:show / position(top/bottom/left/right/center)/ round / closeable / overlay / lock-scroll / safe-area-inset-bottom / destroy-on-close
van-style样式工具类(无组件、用 class)van-hairline--top van-clearfix

表单组件(Form)

标签中文名关键 Props
van-form表单validate-trigger / colon / disabled / readonly / show-error / scroll-to-error / label-align / label-width
van-field输入框v-model / type / label / placeholder / clearable / rules / disabled / readonly / required / max-length / show-word-limit / formatter / left-icon / right-icon / is-link
van-checkbox复选框v-model / disabled / shape(square/round)/ checked-color / icon-size / label-position
van-checkbox-group复选框组v-model / max / direction / disabled
van-radio单选name / disabled / icon-size
van-radio-group单选组v-model / direction / disabled
van-switch开关v-model / disabled / loading / size / active-color / inactive-color
van-stepper步进器v-model / min / max / step / disabled / disable-input / integer / decimal-length
van-rate评分v-model / count / size / color / void-icon / allow-half / readonly / disabled
van-slider滑块v-model / min / max / step / disabled / range(双滑块)/ active-color / button-size / vertical
van-search搜索框v-model / placeholder / background / shape(square/round)/ left-icon / clearable / action-text
van-uploader上传v-model / accept / multiple / max-count / max-size / preview-size / preview-image / before-read / after-read / disabled
van-picker选择器v-model / columns / columns-field-names / title / confirm-button-text / cancel-button-text / loading / readonly
van-picker-groupPicker 组title / tabs / next-step-text
van-date-picker日期选择器v-model / columns-type / min-date / max-date / filter / formatter
van-time-picker时间选择器v-model / columns-type(hour/minute/second)/ min-hour / max-hour / min-minute / max-minute / filter / formatter
van-calendar日历v-model:show / type(single/multiple/range)/ min-date / max-date / formatter / confirm-text / show-confirm / position
van-area省市区v-model / area-list / columns-placeholder / title / confirm-button-text
van-cascader级联v-model / options / field-names / placeholder / title / closeable / show-header
van-number-keyboard数字键盘v-model:show / theme / extra-key / close-button-text / show-delete-key / random-key-order / safe-area-inset-bottom
van-password-input密码输入value / length(默认 6 位)/ mask / focused / gutter
van-signature手写签名type / pen-color / line-width / background-color / tips

反馈组件(Feedback)

标签 / 函数中文名关键 Props / Options
van-action-sheet / showActionSheet动作面板v-model:show / actions / title / cancel-text / description / closeable / close-on-click-action
van-dialog / showDialog / showConfirmDialog对话框v-model:show / title / message / message-align / show-cancel-button / confirm-button-text / cancel-button-text / before-close
van-loading加载type(circular/spinner)/ color / size / text-size / vertical
van-notify / showNotify通知v-model:show / type(primary/success/warning/danger)/ message / color / background / duration
van-overlay遮罩层show / z-index / duration / class-name / custom-style
van-pull-refresh下拉刷新v-model / pulling-text / loosing-text / loading-text / success-text / disabled / animation-duration
van-share-sheet分享面板v-model:show / options / title / cancel-text / description / duration
van-swipe-cell滑动单元格left-width / right-width / disabled / on-close
van-toast / showToast / showSuccessToast / showFailToast / showLoadingToast轻提示message / type(text/loading/success/fail)/ position(top/middle/bottom)/ icon / loading-type / duration / forbidClick / overlay / wordBreak

展示组件(Display)

标签中文名关键 Props
van-badge徽标content / color / max / dot / show-zero / offset
van-barrage弹幕v-model / auto-play / loop / rows / top
van-card商品卡片title / desc / num / price / thumb / origin-price / tag / centered
van-circle环形进度条v-model:current-rate / rate / size / stroke-width / color / layer-color / fill / clockwise
van-collapse / van-collapse-item折叠面板v-model / accordion / border / disabled / title / icon
van-count-down倒计时time / format / auto-start / millisecond
van-divider分割线content-position / dashed / hairline
van-empty空状态image / description / image-size
van-floating-bubble悬浮气泡axis(x/y/xy/lock)/ magnetic / icon
van-floating-panel悬浮面板v-model:height / anchors / duration / content-draggable
van-highlight关键词高亮source-string / keywords / highlight-class / unhighlight-class / case-sensitive / tag
showImagePreview图片预览images / start-position / loop / show-index / show-indicators / close-on-popstate
van-lazyload / v-lazy图片懒加载(指令)需 app.use(Lazyload, { ... }) 注册
van-notice-bar通告栏text / mode(closeable/link)/ color / background / left-icon / delay / speed / scrollable
van-progress进度条percentage / color / track-color / stroke-width / show-pivot / pivot-text / inactive
van-rolling-text数字滚动start-num / target-num / duration / direction / auto-start / stop-order
van-skeleton骨架屏title / avatar / row / row-width / loading / animate
van-sticky粘性布局offset-top / position / container / z-index
van-swipe / van-swipe-item轮播autoplay / duration / initial-swipe / loop / show-indicators / vertical / touchable / lazy-render
van-tag标签type / size / color / plain / round / mark / closeable
van-text-ellipsis文本省略content / rows / expand-text / collapse-text / dots / position
van-watermark水印content / image / image-width / image-height / gap-x / gap-y / opacity / rotate / z-index

导航组件(Navigation)

标签中文名关键 Props
van-action-bar动作栏safe-area-inset-bottom
van-action-bar-icon动作栏图标icon / text / color / dot / badge / to / url
van-action-bar-button动作栏按钮type / text / color / icon / to / url / disabled / loading
van-back-top返回顶部target / right / bottom / offset / immediate
van-grid / van-grid-item宫格column-num / icon-size / gutter / border / center / square / clickable / direction / reverse
van-index-bar / van-index-anchor索引栏sticky / sticky-offset-top / z-index / highlight-color / index-list
van-nav-bar导航栏title / left-text / right-text / left-arrow / fixed / border / placeholder / safe-area-inset-top
van-pagination分页v-model / page-count / total-items / items-per-page / show-page-size / force-ellipses / mode
van-sidebar / van-sidebar-item侧边栏v-model / title / disabled / dot / badge
van-tab / van-tabsTabv-model:active / sticky / swipeable / scrollspy / color / background / line-width / line-height / type(line/card)/ ellipsis / shrink
van-tabbar / van-tabbar-item底部 Tab 栏v-model / fixed / border / route / placeholder / safe-area-inset-bottom / active-color / inactive-color
van-tree-select树形选择v-model:main-active-index / v-model:active-id / items / max / height

业务组件(Business)

标签中文名关键 Props
van-address-edit地址编辑area-list / area-columns-placeholder / address-info / search-result / show-postal / show-delete / show-set-default / disable-area / show-search-result
van-address-list地址列表v-model / list / disabled-list / disabled-text / add-button-text / default-tag-text
van-contact-card联系人卡片type(add/edit)/ name / tel / add-text
van-contact-edit联系人编辑contact-info / is-edit / is-saving / is-deleting / show-set-default / set-default-label / tel-validator
van-contact-list联系人列表v-model / list / add-text / default-tag-text
van-coupon-cell优惠券单元格title / chosen-coupon / coupons / editable / border / currency
van-coupon-list优惠券列表v-model:code / chosen-coupon / coupons / disabled-coupons / enabled-title / disabled-title / exchange-button-text / show-close-button / show-exchange-bar / currency
van-submit-bar提交栏price / label / suffix-label / text-align / button-text / button-type / button-color / tip / tip-icon / currency / decimal-length / safe-area-inset-bottom

常用组件 API 详查

Button(按钮)

Props

参数说明类型默认值
type按钮类型:default / primary / success / warning / dangerstringdefault
size尺寸:large / normal / small / ministringnormal
text按钮文字string-
color按钮颜色(支持 linear-gradient 渐变)string-
icon左侧图标名称或图片链接string-
icon-prefix图标类名前缀stringvan-icon
icon-position图标位置:left / rightstringleft
tagHTML 标签stringbutton
native-type原生 button 标签的 typestringbutton
block是否为块级元素booleanfalse
plain是否为朴素按钮booleanfalse
square是否为方形按钮booleanfalse
round是否为圆形按钮booleanfalse
disabled是否禁用booleanfalse
hairline是否使用 0.5px 边框booleanfalse
loading是否显示加载状态booleanfalse
loading-text加载状态文字string-
loading-type加载图标类型:spinner / circularstringcircular
loading-size加载图标大小number / string20px
url点击后跳转的链接string-
to路由对象(Vue Router)string / object-
replace是否替换历史记录booleanfalse

Events

事件名说明回调参数
click点击触发(loading / disabled 时不触发)event: MouseEvent
touchstart触摸开始event: TouchEvent

Slots

名称说明
default按钮内容
loading自定义加载图标
icon自定义图标

Field(输入框)

Props

参数说明类型默认值
v-model当前输入值number / string-
label左侧文本string-
name表单字段名string-
id输入框 idstringvan-field-n-input
type类型(text / digit / number / tel / password / textarea 等)stringtext
size大小:large / normalstring-
max-length最大字符数number / string-
min最小值(数字类型)number-
max最大值(数字类型)number-
placeholder占位提示string-
border是否显示内边框booleantrue
disabled是否禁用booleanfalse
readonly是否只读booleanfalse
colonlabel 后是否加冒号booleanfalse
required是否显示必填星号boolean / 'auto'null
center内容是否垂直居中booleanfalse
clearable是否启用清除图标booleanfalse
clear-icon清除图标名stringclear
clear-trigger清除时机:always / focusstringfocus
clickable是否启用点击反馈booleanfalse
is-link是否显示右侧箭头并启用点击反馈booleanfalse
autofocus是否自动聚焦booleanfalse
show-word-limit是否显示字数统计booleanfalse
error是否标红booleanfalse
error-message错误提示string-
error-message-align错误对齐:left / center / rightstringleft
formatter格式化函数(val) => string-
format-trigger格式化时机:onChange / onBlurstringonChange
arrow-direction箭头方向:left / up / downstringright
label-classlabel 类名string / array / object-
label-widthlabel 宽度number / string6.2em
label-alignlabel 对齐:left / center / right / topstringleft
input-align输入框对齐stringleft
autosizetextarea 自适应高度boolean / objectfalse
left-icon左侧图标string-
right-icon右侧图标string-
rules校验规则FieldRule[]-
autocompleteHTML autocompletestring-
inputmodeHTML inputmodestring-
rowstextarea 行数number / string-

Events

事件名说明回调参数
update:model-value输入内容变化value: string
focus输入框聚焦event: Event
blur输入框失焦event: Event
clear点击清除按钮event: MouseEvent
click点击组件event: MouseEvent
click-input点击输入区域event: MouseEvent
click-left-icon点击左侧图标event: MouseEvent
click-right-icon点击右侧图标event: MouseEvent
start-validate校验开始-
end-validate校验结束result 对象,含 status(passed / failed / unvalidated)和 errorMessage

Slots

名称说明
label自定义 label
input自定义输入框
left-icon自定义左侧图标
right-icon自定义右侧图标
button自定义右侧按钮
extra自定义右侧额外内容
error-message自定义错误提示

Form(表单)

Props

参数说明类型默认值
label-alignlabel 对齐stringleft
label-widthlabel 宽度number / string6.2em
input-align输入框对齐stringleft
error-message-align错误对齐stringleft
validate-trigger校验时机:onSubmit / onChange / onBlurstring | string[]onBlur
colon是否在 label 后加冒号booleanfalse
disabled是否禁用booleanfalse
readonly是否只读booleanfalse
show-error出错时是否标红booleantrue
show-error-message出错时是否显示错误提示booleantrue
submit-on-enter是否在按下回车键时提交booleantrue
scroll-to-error提交失败时自动滚动到错误项booleanfalse
scroll-to-error-position滚动位置:top / center / bottomstringstart
validate-first是否在校验完一个字段后立即返回booleanfalse

Events

事件名说明回调参数
submit校验通过提交values: 表单数据对象
failed校验失败errorInfo:

Methods(通过 ref 调用)

方法说明类型
submit提交表单(触发 submit 事件)() => void
validate校验表单(name?: string 或 string[]) => Promise<void>
resetValidation重置校验状态(name?: string | string[]) => void
getValidationStatus获取所有字段校验状态() => 字段状态映射对象
scrollToField滚动到指定字段(name: string, alignToTop?: boolean) => void

Cell(单元格)

Props

参数说明类型默认值
title左侧标题string / number-
value右侧内容string / number-
label标题下方描述string-
size尺寸:large / normalstring-
icon左侧图标名string-
icon-prefix图标类名前缀stringvan-icon
url跳转链接string-
to路由对象string / object-
border是否显示下边框booleantrue
replace是否替换历史booleanfalse
clickable是否启用点击反馈booleannull
is-link是否显示右侧箭头 + 点击反馈boolean-
required是否显示必填星号boolean / 'auto'null
center内容垂直居中booleanfalse
arrow-direction箭头方向:left / up / downstringright
title-style标题样式string / array / object-
title-class标题类名string / array / object-
value-class内容类名string / array / object-
label-class描述类名string / array / object-
tagHTML 标签stringdiv

Picker(选择器)

Props

参数说明类型默认值
v-model当前选中值(数组)(number | string)[][]
columns选项数据(一维 / 二维 / 级联)PickerOption[] | PickerOption[][][]
columns-field-names自定义字段名-
title顶部标题string-
confirm-button-text确认按钮文字string确认
cancel-button-text取消按钮文字string取消
show-toolbar是否显示顶部栏booleantrue
loading是否显示加载booleanfalse
readonly是否只读booleanfalse
option-height选项高度number / string44
visible-option-num可见选项数number / string6
swipe-duration滑动惯性时间number / string1000

Events

事件名说明回调参数
confirm确认PickerConfirmEventParams
cancel取消PickerCancelEventParams
change选项变化PickerChangeEventParams
click-option点击选项PickerOption

Slots

名称说明
toolbar自定义顶部栏
title自定义标题
confirm自定义确认按钮
cancel自定义取消按钮
option自定义选项
columns-top顶部内容
columns-bottom底部内容

DatePicker(日期选择器)

Props

参数说明类型默认值
v-model当前日期(数组形式 ['2026', '05', '17'])string[][]
columns-type显示列:year / month / day / hour / minute / secondstring[]['year', 'month', 'day']
min-date最小日期Date10 年前
max-date最大日期Date10 年后
filter过滤函数(type, options) => options-
formatter格式化函数(type, option) => option-
title顶部标题string-

Tabs(标签页)

Props

参数说明类型默认值
v-model:active激活标签的 name 或索引number / string0
type类型:line / cardstringline
color标签主题色string-
background标签栏背景色string-
duration切换动画时长(秒)number / string0.3
line-width底部线宽number / string40px
line-height底部线高number / string3px
title-active-color激活标题颜色string-
title-inactive-color未激活标题颜色string-
swipeable是否启用滑动切换booleanfalse
sticky是否吸顶booleanfalse
scrollspy是否启用滚动导航booleanfalse
animated是否启用切换动画booleanfalse
offset-topsticky 时距顶距离number / string0
ellipsis是否省略过长的标题booleantrue
sticky-offset-topsticky 距顶距离number / string0
shrink是否启用左侧收缩布局booleanfalse
before-change切换前回调(返回 false 阻止)(name) => boolean | Promise-

Events

事件名说明回调参数
change切换 tab 时
click-tab点击 tab 时
disabled点击禁用 tab 时
rendered标签内容首次渲染时(lazy-render 才触发)
scroll滚动时(sticky 模式)

Tabbar(底部 Tab)

Props

参数说明类型默认值
v-model当前激活 tab 的 namenumber / string0
fixed是否固定底部booleantrue
border是否显示上边框booleantrue
z-indexz-indexnumber / string1
active-color激活色string-
inactive-color未激活色string-
route是否启用路由模式booleanfalse
placeholder是否生成占位元素booleanfalse
safe-area-inset-bottom底部安全区适配booleantrue
before-change切换前回调(返回 false 阻止)(name) => boolean | Promise-

Props

参数说明类型默认值
title标题string-
left-text左侧文字string-
right-text右侧文字string-
left-arrow是否显示左侧返回箭头booleanfalse
left-disabled禁用左侧booleanfalse
right-disabled禁用右侧booleanfalse
border是否显示下边框booleantrue
fixed是否固定顶部booleanfalse
placeholder是否生成占位元素(fixed 时)booleanfalse
z-indexz-indexnumber / string1
safe-area-inset-top顶部安全区适配booleanfalse
clickable是否启用点击反馈booleantrue

Events

事件名说明
click-left点击左侧
click-right点击右侧

List(列表)

Props

参数说明类型默认值
v-model:loading是否加载中booleanfalse
v-model:error是否加载失败booleanfalse
finished是否已加载完毕booleanfalse
offset触发距离(px)number / string300
loading-text加载中文字string加载中...
finished-text已加载完毕文字string-
error-text错误提示文字string-
immediate-check初始化是否立即检查booleantrue
direction加载方向:up / downstringdown

Events

事件名说明
load滚动条与底部距离小于 offset 时触发

PullRefresh(下拉刷新)

Props

参数说明类型默认值
v-model是否刷新中booleanfalse
pulling-text下拉中提示string下拉即可刷新...
loosing-text释放提示string释放即可刷新...
loading-text加载中提示string加载中...
success-text刷新成功提示string-
success-duration成功提示展示时长(ms)number / string500
animation-duration动画时长number / string300
head-height顶部内容高度number / string50
pull-distance触发下拉刷新距离number / string-
disabled是否禁用booleanfalse

Events

事件名说明
refresh触发下拉刷新
change距离变化(callback param: distance)

Toast(命令式)

ts
function showToast(options: string | ToastOptions): ToastInstance
function showSuccessToast(options: string | ToastOptions): ToastInstance
function showFailToast(options: string | ToastOptions): ToastInstance
function showLoadingToast(options: string | ToastOptions): ToastInstance
function closeToast(all?: boolean): void
function allowMultipleToast(allow?: boolean): void
function setToastDefaultOptions(type: ToastType | ToastOptions, options?: ToastOptions): void
function resetToastDefaultOptions(type?: ToastType): void

ToastOptions

参数说明类型默认值
type类型:text / loading / success / fail / htmlstringtext
position位置:top / middle / bottomstringmiddle
message内容string / number-
icon自定义图标string-
iconSize图标大小number / string36px
iconPrefix图标前缀stringvan-icon
overlay是否显示遮罩booleanfalse
forbidClick是否禁止背景点击booleanfalse
closeOnClick点击 Toast 后是否关闭booleanfalse
closeOnClickOverlay点击遮罩后是否关闭booleanfalse
loadingType加载图标类型:spinner / circularstringcircular
duration展示时长(ms);0 = 不自动关闭number2000
className自定义类名string / array / object-
onOpened完全展示后触发() => void-
onClose关闭时触发() => void-
transition动画类名stringvan-fade
teleport指定挂载节点string / Elementbody
wordBreak文本换行方式:break-all / break-word / normalstringbreak-all

Dialog(命令式)

ts
function showDialog(options: DialogOptions): Promise<DialogAction>
function showConfirmDialog(options: DialogOptions): Promise<DialogAction>
function closeDialog(): void
function setDialogDefaultOptions(options: DialogOptions): void
function resetDialogDefaultOptions(): void

type DialogAction = 'confirm' | 'cancel'

DialogOptions

参数说明类型默认值
title标题string-
width弹窗宽度number / string320px
message内容(支持 HTML)string-
messageAlign内容对齐:left / center / rightstringcenter
theme主题:default / round-buttonstringdefault
className自定义类名string / array / object-
showConfirmButton是否显示确认按钮booleantrue
showCancelButton是否显示取消按钮booleanfalse
confirmButtonText确认按钮文字string确认
confirmButtonColor确认按钮颜色string#ee0a24
cancelButtonText取消按钮文字string取消
cancelButtonColor取消按钮颜色stringblack
overlay是否显示遮罩booleantrue
overlayClass遮罩自定义类名string-
overlayStyle遮罩自定义样式object-
closeOnPopstate路由变化时关闭booleantrue
closeOnClickOverlay点击遮罩关闭booleanfalse
lockScroll是否锁定背景滚动booleantrue
beforeClose关闭前回调(返回 false 阻止)(action) => boolean 或 Promise<boolean>-
allowHtml是否允许 message 解析 HTMLbooleanfalse
transition动画类名stringvan-dialog-bounce
teleport挂载节点string / Elementbody

Notify(命令式)

ts
function showNotify(options: string | NotifyOptions): NotifyInstance
function closeNotify(): void
function setNotifyDefaultOptions(options: NotifyOptions): void
function resetNotifyDefaultOptions(): void

NotifyOptions

参数说明类型默认值
type类型:primary / success / warning / dangerstringdanger
message内容string / number-
color字体颜色string-
background背景色string-
duration展示时长(ms)number3000
className自定义类名string / array / object-
lockScroll是否锁定背景滚动booleanfalse
onClick点击回调(event) => void-
onOpened完全展示后回调() => void-
onClose关闭时回调() => void-

ImagePreview(命令式)

ts
function showImagePreview(options: ImagePreviewOptions | string[]): ImagePreviewInstance

ImagePreviewOptions

参数说明类型默认值
images图片数组string[][]
startPosition起始索引number0
swipeDuration切换动画时长(ms)number / string300
showIndex是否显示索引booleantrue
showIndicators是否显示指示器booleanfalse
loop是否循环booleantrue
closeable是否显示关闭按钮booleanfalse
closeIcon关闭图标stringclear
closeIconPosition关闭按钮位置:top-left / top-right / bottom-left / bottom-rightstringtop-right
closeOnPopstate路由变化时关闭booleantrue
beforeClose关闭前回调(action, { index }) => boolean-
onClose关闭时回调() => void-
onChange切换时回调(index) => void-
onScale缩放时回调({ index, scale }) => void-
onLongPress长按时回调({ index }) => void-

ConfigProvider 全局配置

Props

参数说明类型默认值
theme主题:light / darkstringlight
theme-vars主题变量(camelCase)ConfigProviderThemeVars-
theme-vars-dark仅深色模式生效的变量ConfigProviderThemeVars-
theme-vars-light仅浅色模式生效的变量ConfigProviderThemeVars-
theme-vars-scope变量作用域:global / localstringlocal
icon-prefix图标前缀stringvan-icon
tagHTML 标签stringdiv
z-index全局 z-index 起始值number-
ts
import type { ConfigProviderThemeVars } from 'vant'

const themeVars: ConfigProviderThemeVars = {
  // 基础变量
  primaryColor: '#07c160',
  successColor: '#07c160',
  warningColor: '#ff976a',
  dangerColor: '#ee0a24',
  textColor: '#323233',
  backgroundColor: '#f7f8fa',

  // 组件变量(任意组件 + 任意属性的 camelCase)
  buttonPrimaryBackground: '#07c160',
  buttonPrimaryBorderColor: '#07c160',
  tabActiveTextColor: '#07c160',
  navBarBackground: '#fff',
  cellGroupBackground: '#fff',
  fieldInputTextColor: '#323233',
  // ... 700+ 变量
}

Locale 国际化 API

ts
import { Locale, useCurrentLang } from 'vant'

// 切换语言(覆盖式)
Locale.use(lang: string, messages: Record<string, any>): void

// 追加 / 覆盖部分文案
Locale.add(messages: Record<string, Record<string, any>>): void

// 获取当前语言(Composable)
const currentLang: Ref<string> = useCurrentLang()

支持的语言文件:

ts
// vant/es/locale/lang/ 下的所有文件
import zhCN from 'vant/es/locale/lang/zh-CN'
import zhHK from 'vant/es/locale/lang/zh-HK'
import zhTW from 'vant/es/locale/lang/zh-TW'
import enUS from 'vant/es/locale/lang/en-US'
import jaJP from 'vant/es/locale/lang/ja-JP'
import koKR from 'vant/es/locale/lang/ko-KR'
import frFR from 'vant/es/locale/lang/fr-FR'
import deDE from 'vant/es/locale/lang/de-DE'
import esES from 'vant/es/locale/lang/es-ES'
import itIT from 'vant/es/locale/lang/it-IT'
import ptBR from 'vant/es/locale/lang/pt-BR'
import ruRU from 'vant/es/locale/lang/ru-RU'
import arSA from 'vant/es/locale/lang/ar-SA'  // RTL
import idID from 'vant/es/locale/lang/id-ID'
import viVN from 'vant/es/locale/lang/vi-VN'
import thTH from 'vant/es/locale/lang/th-TH'
import trTR from 'vant/es/locale/lang/tr-TR'
import plPL from 'vant/es/locale/lang/pl-PL'
import roRO from 'vant/es/locale/lang/ro-RO'
import nlNL from 'vant/es/locale/lang/nl-NL'
import svSE from 'vant/es/locale/lang/sv-SE'
import heIL from 'vant/es/locale/lang/he-IL'  // RTL
import hiIN from 'vant/es/locale/lang/hi-IN'
import faIR from 'vant/es/locale/lang/fa-IR'  // RTL
import csCZ from 'vant/es/locale/lang/cs-CZ'
import bgBG from 'vant/es/locale/lang/bg-BG'
import elGR from 'vant/es/locale/lang/el-GR'
import laLA from 'vant/es/locale/lang/la-LA'
import isIS from 'vant/es/locale/lang/is-IS'
import mmMN from 'vant/es/locale/lang/mm-MN'
import kmKH from 'vant/es/locale/lang/km-KH'
import bnBD from 'vant/es/locale/lang/bn-BD'
import daDK from 'vant/es/locale/lang/da-DK'
import nbNO from 'vant/es/locale/lang/nb-NO'
import eoEO from 'vant/es/locale/lang/eo-EO'
import srRS from 'vant/es/locale/lang/sr-RS'
import ukUA from 'vant/es/locale/lang/uk-UA'
import kkKZ from 'vant/es/locale/lang/kk-KZ'

TypeScript 类型

ts
import type {
  // 组件实例
  FormInstance,
  FieldInstance,
  PickerInstance,
  DatePickerInstance,
  ToastInstance,
  DialogInstance,
  NotifyInstance,
  ImagePreviewInstance,
  CountDownInstance,
  CalendarInstance,
  SwipeInstance,
  TabsInstance,

  // Props 类型
  ButtonProps,
  FieldProps,
  CellProps,
  PickerProps,
  FormProps,

  // 校验规则
  FieldRule,
  FieldValidationStatus,

  // Picker / DatePicker
  PickerOption,
  PickerColumn,
  PickerConfirmEventParams,
  PickerCancelEventParams,
  PickerChangeEventParams,
  PickerFieldNames,

  // 命令式 API 选项
  ToastOptions,
  ToastType,
  DialogOptions,
  DialogAction,
  NotifyOptions,
  NotifyType,
  ImagePreviewOptions,

  // ConfigProvider
  ConfigProviderProps,
  ConfigProviderTheme,
  ConfigProviderThemeVars,
  ConfigProviderThemeVarsScope,

  // 业务组件
  AddressEditInfo,
  AddressEditSearchItem,
  AddressListAddress,
  ContactEditInfo,
  ContactListItem,
  CouponInfo,

  // 通用工具类型
  Numeric,
} from 'vant'

类型化 ref(推荐写法)

vue
<script setup lang="ts">
import { useTemplateRef } from 'vue'
import type { FormInstance, FieldInstance } from 'vant'

const formRef = useTemplateRef<FormInstance>('formRef')
const fieldRef = useTemplateRef<FieldInstance>('fieldRef')

async function onSubmit() {
  // 自动类型推导:validate() / resetValidation() / scrollToField()
  await formRef.value?.validate()
}
</script>

<template>
  <van-form ref="formRef">
    <van-field ref="fieldRef" v-model="value" />
  </van-form>
</template>

FieldRule 类型

ts
type FieldRuleMessage = string | ((value: any, rule: FieldRule) => string)
type FieldRuleValidator = (value: any, rule: FieldRule) => boolean | string | Promise<boolean | string>
type FieldRuleFormatter = (value: any, rule: FieldRule) => any

interface FieldRule {
  pattern?: RegExp
  trigger?: 'onBlur' | 'onChange' | 'onSubmit'
  message?: FieldRuleMessage
  required?: boolean
  validator?: FieldRuleValidator
  formatter?: FieldRuleFormatter
  min?: number
  max?: number
  validateEmpty?: boolean
}

Composables(@vant/use)

Vant 4 抽出独立 @vant/use 包提供可复用的 composables(部分已合并到 vant 主包):

Composable签名用途
useClickAwayuseClickAway(target, listener, options?)监听点击元素外部
useCountDownuseCountDown(options)倒计时(与 CountDown 组件配合)
useCustomFieldValueuseCustomFieldValue(getValue)自定义表单字段值(在 Field input 插槽中)
useEventListeneruseEventListener(type, listener, options?)监听 DOM 事件
usePageVisibilityusePageVisibility()监听 document.visibilityState
useRafuseRaf(fn, options?)requestAnimationFrame 循环
useRectuseRect(target)获取元素 getBoundingClientRect()
useRelationuseRelation(parent, child)父子组件互相通讯(内部使用)
useScrollParentuseScrollParent(element)找到最近的可滚动父元素
useToggleuseToggle(initial?)切换 boolean 状态
useWindowSizeuseWindowSize()监听窗口大小变化

示例

ts
import {
  useClickAway,
  useCountDown,
  useEventListener,
  usePageVisibility,
  useRect,
  useScrollParent,
  useToggle,
  useWindowSize,
} from 'vant'

// 点击外部关闭
useClickAway(targetRef, () => {
  show.value = false
})

// 倒计时
const countDown = useCountDown({
  time: 3 * 60 * 60 * 1000, // 3 小时
  onChange(current) {
    console.log(current.minutes)
  },
})
countDown.start()
countDown.pause()
countDown.reset()

// 页面可见性
const visibility = usePageVisibility()
watch(visibility, (val) => {
  if (val === 'hidden') {
    // 页面切走
  }
})

// 元素矩形
const rect = useRect(targetRef)
console.log(rect.width, rect.height)

// 窗口大小
const { width, height } = useWindowSize()

// 状态切换
const [show, toggle] = useToggle(false)
toggle() // 切换
toggle(true) // 显式设置

700+ CSS 变量入口

完整变量源码

Vant 4 CSS 变量源 —— Less 源文件,700+ 行。

基础变量(部分速查)

less
// 颜色调色板(Color Palette)
--van-black: #000;
--van-white: #fff;
--van-gray-1: #f7f8fa;
--van-gray-2: #f2f3f5;
--van-gray-3: #ebedf0;
--van-gray-4: #dcdee0;
--van-gray-5: #c8c9cc;
--van-gray-6: #969799;
--van-gray-7: #646566;
--van-gray-8: #323233;
--van-red: #ee0a24;
--van-blue: #1989fa;
--van-orange: #ff976a;
--van-orange-dark: #ed6a0c;
--van-orange-light: #fffbe8;
--van-green: #07c160;

// 主题颜色(Theme Colors)
--van-primary-color: var(--van-blue);
--van-success-color: var(--van-green);
--van-danger-color: var(--van-red);
--van-warning-color: var(--van-orange);
--van-text-color: var(--van-gray-8);
--van-text-color-2: var(--van-gray-6);
--van-text-color-3: var(--van-gray-5);
--van-active-color: var(--van-gray-2);
--van-active-opacity: 0.7;
--van-disabled-opacity: 0.5;
--van-background: var(--van-gray-1);
--van-background-2: var(--van-white);
--van-background-3: var(--van-gray-2);

// 边框(Border)
--van-border-color: var(--van-gray-3);
--van-border-width: 1px;
--van-border-radius-sm: 2px;
--van-border-radius-md: 4px;
--van-border-radius-lg: 8px;
--van-border-radius-max: 999px;

// 字体(Font)
--van-font-bold: 600;
--van-font-size-xs: 10px;
--van-font-size-sm: 12px;
--van-font-size-md: 14px;
--van-font-size-lg: 16px;
--van-line-height-xs: 14px;
--van-line-height-sm: 18px;
--van-line-height-md: 20px;
--van-line-height-lg: 22px;
--van-base-font: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, Segoe UI, Arial, Roboto, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif;
--van-price-integer-font: avenir-heavy, 'PingFang SC', helvetica, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif;

// 间距(Padding)
--van-padding-base: 4px;
--van-padding-xs: 8px;
--van-padding-sm: 12px;
--van-padding-md: 16px;
--van-padding-lg: 24px;
--van-padding-xl: 32px;

// 动画(Animation)
--van-duration-base: 0.3s;
--van-duration-fast: 0.2s;
--van-ease-out: ease-out;
--van-ease-in: ease-in;

组件变量命名规则

less
// 1. 普通:--van-{component}-{property}
--van-button-default-color
--van-cell-text-color

// 2. 带状态:--van-{component}-{state}-{property}
--van-button-primary-background
--van-tab-active-text-color

// 3. 带尺寸:--van-{component}-{size}-{property}
--van-button-large-min-width
--van-cell-large-vertical-padding

类型化模板 ref 完整模板

ts
// <script setup lang="ts"> 中的写法
import { useTemplateRef } from 'vue'
import type {
  FormInstance,
  FieldInstance,
  PickerInstance,
  DatePickerInstance,
  CalendarInstance,
  SwipeInstance,
  TabsInstance,
  CountDownInstance,
  ImagePreviewInstance,
} from 'vant'

// 表单类
const formRef = useTemplateRef<FormInstance>('formRef')
const fieldRef = useTemplateRef<FieldInstance>('fieldRef')

// 选择类
const pickerRef = useTemplateRef<PickerInstance>('pickerRef')
const datePickerRef = useTemplateRef<DatePickerInstance>('datePickerRef')
const calendarRef = useTemplateRef<CalendarInstance>('calendarRef')

// 容器类
const swipeRef = useTemplateRef<SwipeInstance>('swipeRef')
const tabsRef = useTemplateRef<TabsInstance>('tabsRef')

// 计时类
const countDownRef = useTemplateRef<CountDownInstance>('countDownRef')

// 业务类
const imagePreviewRef = useTemplateRef<ImagePreviewInstance>('imagePreviewRef')

// 调用实例方法
formRef.value?.validate()
fieldRef.value?.focus()
swipeRef.value?.next()
swipeRef.value?.prev()
swipeRef.value?.swipeTo(2)
tabsRef.value?.resize()
tabsRef.value?.scrollTo(1)
countDownRef.value?.start()
countDownRef.value?.pause()
countDownRef.value?.reset()

命令式 API 默认配置 setter

ts
import {
  setToastDefaultOptions,
  resetToastDefaultOptions,
  setDialogDefaultOptions,
  resetDialogDefaultOptions,
  setNotifyDefaultOptions,
  resetNotifyDefaultOptions,
  setImagePreviewDefaultOptions,
  resetImagePreviewDefaultOptions,
} from 'vant'

// Toast 默认配置
setToastDefaultOptions({ duration: 1500 })
setToastDefaultOptions('loading', { forbidClick: true, duration: 0 })
resetToastDefaultOptions()
resetToastDefaultOptions('loading')

// Dialog 默认配置
setDialogDefaultOptions({
  width: '90%',
  confirmButtonColor: '#07c160',
  beforeClose: async (action) => action === 'confirm',
})

// Notify 默认配置
setNotifyDefaultOptions({
  duration: 4000,
})

图标库(1000+ 图标)

Vant 4 内置 1000+ 图标——通过 van-icon 组件的 name 属性使用。部分常用图标速查

操作类

name含义
arrow / arrow-left / arrow-up / arrow-down箭头
cross / close关闭
add / plus添加
minus减少
edit编辑
delete / delete-o删除
search搜索
filter-o筛选
share-o分享
comment-o评论
like / like-o点赞
star / star-o收藏
home-o首页
user-o / friends-o用户 / 朋友
setting-o设置
sign签到

提示类

name含义
success成功
fail失败
warning / warning-o警告
info / info-o信息
question / question-o疑问
passed已通过
clear清除
checked已选
close关闭

业务类(电商)

name含义
shopping-cart-o购物车
cart-o购物车
gold-coin-o金币
balance-pay余额支付
balance-o余额
coupon-o优惠券
gift-o礼品
location-o位置
logistics物流
order订单
pending-payment待支付
paid已支付
points积分
medal-o勋章
label-o标签

完整图标列表

参见 Vant Icon 文档 —— 在线预览所有图标 + 复制名称。

自定义图标前缀

vue
<template>
  <van-config-provider icon-prefix="my-icon">
    <!-- 现在 van-icon 不再走 van-icon-* 类名、而走 my-icon-* -->
    <van-icon name="home" />
  </van-config-provider>
</template>

或者用 van-iconclass-prefix 属性单独覆盖。

工具函数

数字格式化

ts
// Vant 不导出公共数字格式化工具——可以用 SubmitBar 的内部逻辑
// 价格单位:分(3050 → ¥30.50)
function formatPrice(price: number, decimalLength = 2): string {
  return (price / 100).toFixed(decimalLength)
}

// 千分位
function thousandSeparator(num: number | string): string {
  return String(num).replace(/\B(?=(\d{3})+(?!\d))/g, ',')
}

自定义校验工具(FieldRule 复用)

ts
import type { FieldRule } from 'vant'

// 手机号
export const phoneRule: FieldRule = {
  pattern: /^1\d{10}$/,
  message: '请输入正确的手机号',
}

// 邮箱
export const emailRule: FieldRule = {
  pattern: /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,}$/,
  message: '请输入正确的邮箱',
}

// 身份证
export const idCardRule: FieldRule = {
  pattern: /^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/,
  message: '请输入正确的身份证号',
}

// 密码强度(8 位以上、含字母数字)
export const passwordRule: FieldRule = {
  pattern: /^(?=.*[A-Za-z])(?=.*\d).{8,}$/,
  message: '密码至少 8 位、包含字母和数字',
}

与 vue-i18n 集成

ts
// main.ts
import { createApp } from 'vue'
import { createI18n } from 'vue-i18n'
import { Locale } from 'vant'
import enUS from 'vant/es/locale/lang/en-US'
import zhCN from 'vant/es/locale/lang/zh-CN'
import App from './App.vue'

const i18n = createI18n({
  locale: 'zh-CN',
  fallbackLocale: 'en-US',
  legacy: false,
  messages: {
    'zh-CN': { hello: '你好' },
    'en-US': { hello: 'Hello' },
  },
})

// 同步 vue-i18n locale 变化到 Vant Locale
const vantLocales = {
  'zh-CN': zhCN,
  'en-US': enUS,
}

i18n.global.locale.value = 'zh-CN'
Locale.use('zh-CN', zhCN)

// 切换语言
function switchLanguage(lang: 'zh-CN' | 'en-US') {
  i18n.global.locale.value = lang
  Locale.use(lang, vantLocales[lang])
}

createApp(App).use(i18n).mount('#app')

相关链接