
Vant Vue3
- 18 installs
- 3 repo stars
- Updated July 29, 2026
- full-statck-skills/vue-ui-skills
Guidance for the Vant Vue 3 mobile UI library, covering components, theme customization and mobile-first interfaces.
About
Provides structured guidance for building mobile-first Vue 3 interfaces with Vant components and theme customization. A developer uses it when implementing touch-oriented mobile UIs with Vant.
- Covers van-button, van-cell, van-form, van-dialog and van-popup
- Includes ConfigProvider theme variables and mobile-first patterns
Vant Vue3 by the numbers
- 18 all-time installs (skills.sh)
- Ranked #1,577 of 2,245 Frontend Development skills by installs in the Skillselion catalog
- Data as of Jul 30, 2026 (Skillselion catalog sync)
npx skills add https://github.com/full-statck-skills/vue-ui-skills --skill vant-vue3Add your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 18 |
|---|---|
| repo stars | ★ 3 |
| Last updated | July 29, 2026 |
| Repository | full-statck-skills/vue-ui-skills ↗ |
What it does
Guidance for the Vant Vue 3 mobile UI library, covering components, theme customization and mobile-first interfaces.
Files
Vant of Vue 3
When to use this skill
Use this skill whenever the user is working with Vant for Vue 3 or asks for:
- Vant installation, setup, or project initialization
- Vue 3 mobile UI implementation with
vant van-button,van-cell,van-form,van-dialog,van-popup,van-toast- Vant
ConfigProvider, theme variables, or theme customization - Mobile-first page structure, touch-oriented UI, or form flows based on Vant
- Converting generic Vue 3 UI to Vant component usage
- Reviewing or fixing existing Vant Vue 3 code
Trigger terms include:
vantvant vue3Vant of Vue 3.0van-button,van-form,van-cell,van-dialog,van-toast,van-popupConfigProvidertheme-varsvant 组件Vant 主题定制
Scope and alignment
This skill is aligned to the official Vant documentation entry points:
- Official website: https://vant-ui.github.io/
- Official guide: https://vant-ui.github.io/vant/#/zh-CN
The local skill content only claims coverage for files that actually exist in this skill directory. Do not reference non-existent local files. If the requested Vant component is not covered by a local example file, use the official guide as the primary reference and reuse the closest local pattern.
For the exact local-to-official mapping, read:
references/official-mapping.md
How to use this skill
Step 1: Identify the request area
Map the user request to one of these areas:
1. Quick start / setup
- Installing Vant
- Importing styles
- Full import vs on-demand import
- Vue 3 project bootstrap
2. Component implementation
- Button
- Cell
- Form
- Dialog
- Toast
- Popup
3. Global config and theming
ConfigProvidertheme-vars- Theme customization
4. API lookup
- Common props
- Component props/events/methods
- Global config API
5. Template or scaffold
- Project setup template
- Reusable component structure
Step 2: Load only the matching files
Use the smallest relevant set of files.
A. Quick start / setup
examples/getting-started/installation.mdexamples/getting-started/basic-usage.mdtemplates/project-setup.md
Use these when the user asks how to install Vant, register components, import CSS, or start a Vue 3 + Vant project.
B. Covered component examples
Use only the component file that matches the user request:
- Button →
examples/components/button.md - Cell →
examples/components/cell.md - Form →
examples/components/form.md - Dialog →
examples/components/dialog.md - Popup →
examples/components/popup.md - Toast →
examples/components/toast.md
C. Global config and theme
api/config-provider.mdexamples/advanced/theme-customization.md
Use these for ConfigProvider, dark/light theme handling, theme-vars, CSS variables, or global UI behavior.
D. API lookup
api/components.mdapi/config-provider.md
Use these when the user needs prop names, event names, method names, or a quick API summary.
E. Official navigation and coverage boundaries
references/official-mapping.md
Use this file when:
- You need to confirm what this skill covers locally
- You need to route the user from an official Vant section to a local file
- You need to handle a Vant component that is not yet covered by a local example
Step 3: Follow the response workflow
When answering with this skill:
1. Confirm the target is Vant for Vue 3, not another Vue UI library. 2. Pick the matching local example or API file. 3. Keep code examples in Vue 3 Composition API style. 4. Preserve Vant naming and usage conventions:
- import from
vant - use
van-components in templates - import
vant/lib/index.csswhere setup requires it
5. Prefer mobile-first structure and touch-oriented interaction patterns. 6. If the requested component is not covered locally:
- say that the local skill does not contain a dedicated example file for that component
- route via
references/official-mapping.md - use the official guide as the primary source of truth
- adapt the closest covered local example style instead of inventing fake local files
Local navigation map
This is the actual local navigation surface for the skill.
Getting started
examples/getting-started/installation.mdexamples/getting-started/basic-usage.mdtemplates/project-setup.md
Components covered locally
examples/components/button.mdexamples/components/cell.mdexamples/components/form.mdexamples/components/dialog.mdexamples/components/popup.mdexamples/components/toast.md
Theme and global configuration
api/config-provider.mdexamples/advanced/theme-customization.md
API summaries
api/components.mdapi/config-provider.md
Official mapping
references/official-mapping.md
Working rules
Do
- Use only local files that actually exist
- Keep answers anchored to the official Vant guide structure
- Prefer concrete component code over abstract explanation
- Use
script setupstyle for Vue 3 examples unless the user already uses another style - Mention
ConfigProviderwhen the user asks about global theme or locale-like app-wide config - Keep code samples runnable and focused
Do not
- Do not reference
icon.md,tabs.md,navbar.md, or other files that do not exist in this skill - Do not pretend this skill has full local coverage for every Vant component
- Do not mix Vant patterns with Element Plus, Ant Design Vue, or other UI libraries
- Do not output generic Vue UI advice when the user explicitly asks for Vant
Answer patterns
If the user asks for setup
Load:
examples/getting-started/installation.mdtemplates/project-setup.md
Return:
- install command
- CSS import
- registration strategy
- minimal Vue 3 + Vant starter
If the user asks for a covered component
Load:
- the matching file under
examples/components/ api/components.mdif props/events are involved
Return:
- minimal example first
- then props/events/method notes
- then usage pitfalls if relevant
If the user asks for theme customization
Load:
api/config-provider.mdexamples/advanced/theme-customization.md
Return:
ConfigProviderusagetheme-varsexample- CSS variable strategy
- scope and inheritance notes
If the user asks for an uncovered Vant component
Load:
references/official-mapping.md- nearest covered local file
Return:
- explicit note that the local skill has no dedicated example file for that component
- route to the official Vant guide section
- provide a Vant-consistent example following the same conventions used in this skill
Quality checklist
Before responding, verify that:
- the answer is specifically for Vant of Vue 3
- all referenced local files exist
- imports come from
vant - examples use Vue 3 syntax
- setup examples include CSS import where needed
- theme answers use
ConfigProvider/theme-varsconsistently
Resources
- Official website: https://vant-ui.github.io/
- Official guide: https://vant-ui.github.io/vant/#/zh-CN
- Local official mapping:
references/official-mapping.md
Keywords
Vant, Vant Vue 3, Vant of Vue 3.0, Vue 3 mobile UI, van-button, van-cell, van-form, van-dialog, van-toast, van-popup, ConfigProvider, theme-vars, mobile-first UI, Vant theme, Vant setup, Vant component library, vant 组件, vant vue3, 移动端组件库, 按钮, 单元格, 表单, 对话框, 提示, 弹出层, 主题定制
能力边界
✅ 适用场景
- 当你需要使用此技能对应的技术栈时
- 当项目需要遵循最佳实践时
- 当需要快速上手或深入理解核心概念时
⚠️ 需要注意
- 复杂业务逻辑需要结合具体场景调整
- 性能优化需要根据实际数据量评估
❌ 不适用场景
- 不相关的技术栈或框架
- 需要完全自定义的特殊场景
常见陷阱 (Gotchas)
1. 版本兼容性:注意框架版本与依赖库的兼容性,不同版本 API 可能有差异 2. 配置文件格式:配置文件格式错误是最常见的问题,建议使用编辑器的语法检查 3. 环境变量:确保所有必要的环境变量已正确设置,敏感信息不要硬编码 4. 依赖冲突:多版本共存时注意依赖冲突,使用 lock 文件锁定版本 5. 性能陷阱:大数据量场景下注意性能优化,避免 N+1 查询等常见问题
Components API | 组件 API
适用范围:本文件只总结当前本地 skill 已覆盖的组件与能力,不声称覆盖全部 Vant 组件。
当前本地覆盖组件:
- Button
- Cell
- Form / Field
- Dialog
- Toast
- Popup
关联示例文件:
- Button →
examples/components/button.md - Cell →
examples/components/cell.md - Form →
examples/components/form.md - Dialog →
examples/components/dialog.md - Toast →
examples/components/toast.md - Popup →
examples/components/popup.md
Common usage rules
- 所有组件示例默认使用 Vue 3
script setup - 所有组件从
vant导入 - 交互型组件优先保持移动端使用场景
- 需要主题配置时,配合
api/config-provider.md
Button API summary
Use when:
- 需要操作按钮
- 需要提交、确认、触发事件入口
Common props:
type:primary/success/warning/danger/defaultsize:large/normal/small/minishape:square/roundplain: plain styledisabled: disabled stateloading: loading stateicon: icon name
Common events:
@click
See also:
examples/components/button.md
Cell API summary
Use when:
- 需要列表项、信息项、跳转入口
Common props:
titlevaluelabeliconis-linkarrow-direction
Common events:
@click
Related components:
CellGroup
See also:
examples/components/cell.md
Form API summary
Use when:
- 需要登录、注册、资料编辑、校验提交
Core components:
FormFieldCellGroupButton
Common events:
@submit@failed
Common methods:
validate()resetValidation()
Common field props:
v-modelnamelabelplaceholder:rulestypedisabled
See also:
examples/components/form.md
Dialog API summary
Use when:
- 需要确认、警告、阻断式提示、带表单输入的弹窗
Component props:
v-model:showtitlemessageshow-cancel-buttonconfirm-button-textcancel-button-text
Component events:
@confirm@cancel
Programmatic APIs:
showDialog(options)showConfirmDialog(options)
See also:
examples/components/dialog.md
Toast API summary
Use when:
- 需要轻提示、成功提示、失败提示、加载提示
Programmatic APIs:
showToast(message | options)showSuccessToast(message)showFailToast(message)showLoadingToast(message)
Common options:
typemessagedurationposition
Component usage:
van-toastwithv-model:show
See also:
examples/components/toast.md
Popup API summary
Use when:
- 需要底部弹层、侧边滑出层、中间弹层、可关闭容器
Common props:
v-model:showpositionroundcloseableclose-icon-positionoverlay
Common events:
@close
See also:
examples/components/popup.md
Selection guide
- If the user asks for a primary action control, start with Button
- If the user asks for list-style navigation or info rows, start with Cell
- If the user asks for data entry or validation, start with Form
- If the user asks for confirmation or interruption, start with Dialog
- If the user asks for lightweight feedback, start with Toast
- If the user asks for overlay content or slide-up panels, start with Popup
ConfigProvider API | ConfigProvider API
官方文档入口: https://vant-ui.github.io/vant/#/zh-CN 官方对应章节: ConfigProvider
API Reference
ConfigProvider component API for global configuration.
ConfigProvider
Provides global configuration for Vant components.
Props:
theme: Theme configuration (light, dark)theme-vars: Custom theme variablestag: Root element tagz-index: Z-index for popup components
Example: Basic Usage
<template>
<van-config-provider :theme-vars="themeVars">
<App />
</van-config-provider>
</template>
<script setup>
import { ConfigProvider as VanConfigProvider } from 'vant'
const themeVars = {
primaryColor: '#07c160',
successColor: '#07c160',
dangerColor: '#ee0a24'
}
</script>Example: Theme Variables
<template>
<van-config-provider :theme-vars="themeVars">
<van-button type="primary">Button</van-button>
</van-config-provider>
</template>
<script setup>
import { ConfigProvider as VanConfigProvider, Button as VanButton } from 'vant'
const themeVars = {
buttonPrimaryBackground: '#07c160',
buttonPrimaryBorderColor: '#07c160'
}
</script>Key Points
- Wrap app with ConfigProvider for global config
- Use theme-vars prop for theme customization
- Use theme prop for light/dark theme
- ConfigProvider affects all child components
- Can nest ConfigProviders for different scopes
- Theme variables use CSS variables
Theme Customization | 主题定制
官方文档入口: https://vant-ui.github.io/vant/#/zh-CN 官方对应章节: ConfigProvider / 主题定制
Instructions
This example demonstrates how to customize Vant theme.
Key Concepts
- Using ConfigProvider
- Customizing theme variables
- CSS variables
- Theme switching
Example: Basic Theme Customization
<template>
<van-config-provider :theme-vars="themeVars">
<van-button type="primary">Primary Button</van-button>
</van-config-provider>
</template>
<script setup>
import { ConfigProvider as VanConfigProvider, Button as VanButton } from 'vant'
const themeVars = {
primaryColor: '#07c160',
successColor: '#07c160',
dangerColor: '#ee0a24'
}
</script>Example: Customizing Multiple Variables
<template>
<van-config-provider :theme-vars="themeVars">
<van-button type="primary">Button</van-button>
<van-cell title="Cell" />
</van-config-provider>
</template>
<script setup>
import { ConfigProvider as VanConfigProvider, Button as VanButton, Cell as VanCell } from 'vant'
const themeVars = {
buttonPrimaryBackground: '#07c160',
buttonPrimaryBorderColor: '#07c160',
cellFontSize: '16px',
cellTextColor: '#323233'
}
</script>Example: Using CSS Variables
<template>
<van-config-provider :theme-vars="themeVars">
<App />
</van-config-provider>
</template>
<script setup>
import { ConfigProvider as VanConfigProvider } from 'vant'
const themeVars = {
primaryColor: 'var(--my-primary-color)',
successColor: 'var(--my-success-color)'
}
</script>
<style>
:root {
--my-primary-color: #07c160;
--my-success-color: #07c160;
}
</style>Key Points
- Use
ConfigProviderwiththeme-varsprop - Customize theme variables via
theme-varsproperty - Theme changes apply to all child components
- Supports CSS variables
- Can switch themes dynamically
- Theme variables follow Vant naming convention
Related local files
- Config API:
api/config-provider.md - Project scaffold:
templates/project-setup.md
Button | 按钮
官方文档入口: https://vant-ui.github.io/vant/#/zh-CN 官方对应章节: Button / 按钮
Instructions
This example demonstrates how to use the Button component in Vant.
Key Concepts
- Button types (primary, success, warning, danger)
- Button sizes (large, normal, small, mini)
- Button shapes (square, round)
- Button states (disabled, loading)
- Button with icons
- Button groups
Example: Button Types
<template>
<van-button type="primary">Primary</van-button>
<van-button type="success">Success</van-button>
<van-button type="warning">Warning</van-button>
<van-button type="danger">Danger</van-button>
<van-button type="default">Default</van-button>
</template>
<script setup>
import { Button as VanButton } from 'vant'
</script>Example: Button Sizes
<template>
<van-button type="primary" size="large">Large</van-button>
<van-button type="primary" size="normal">Normal</van-button>
<van-button type="primary" size="small">Small</van-button>
<van-button type="primary" size="mini">Mini</van-button>
</template>
<script setup>
import { Button as VanButton } from 'vant'
</script>Example: Button with Icon
<template>
<van-button type="primary" icon="plus">Add</van-button>
<van-button type="primary" icon="search">Search</van-button>
</template>
<script setup>
import { Button as VanButton } from 'vant'
</script>Example: Loading State
<template>
<van-button
type="primary"
:loading="loading"
loading-text="Loading..."
@click="handleClick"
>
Click Me
</van-button>
</template>
<script setup>
import { ref } from 'vue'
import { Button as VanButton } from 'vant'
const loading = ref(false)
const handleClick = () => {
loading.value = true
setTimeout(() => {
loading.value = false
}, 2000)
}
</script>Example: Disabled Button
<template>
<van-button type="primary" disabled>Disabled</van-button>
<van-button :disabled="disabled">Toggle Disabled</van-button>
</template>
<script setup>
import { ref } from 'vue'
import { Button as VanButton } from 'vant'
const disabled = ref(false)
</script>Example: Button Group
<template>
<van-button-group>
<van-button type="primary">Left</van-button>
<van-button type="primary">Middle</van-button>
<van-button type="primary">Right</van-button>
</van-button-group>
</template>
<script setup>
import { Button as VanButton, ButtonGroup as VanButtonGroup } from 'vant'
</script>Key Points
- Use
typeprop for button style (primary, success, warning, danger, default) - Use
sizeprop for button size (large, normal, small, mini) - Use
iconprop for icon buttons - Use
loadingprop for loading state - Use
disabledprop to disable button - Use
van-button-groupfor button groups - Button supports all standard HTML button attributes
Related local files
- API summary:
api/components.md - Form submit button pattern:
examples/components/form.md
Cell | 单元格
官方文档入口: https://vant-ui.github.io/vant/#/zh-CN 官方对应章节: Cell / 单元格
Instructions
This example demonstrates how to use the Cell component in Vant.
Key Concepts
- Basic Cell
- Cell with value
- Cell with icon
- Cell with arrow
- Cell with click handler
- Cell groups
Example: Basic Cell
<template>
<van-cell title="Cell Title" />
<van-cell title="Cell Title" value="Content" />
</template>
<script setup>
import { Cell as VanCell } from 'vant'
</script>Example: Cell with Icon
<template>
<van-cell
title="Cell Title"
value="Content"
icon="location-o"
/>
</template>
<script setup>
import { Cell as VanCell } from 'vant'
</script>Example: Cell with Arrow
<template>
<van-cell title="Cell Title" is-link />
<van-cell title="Cell Title" is-link arrow-direction="down" />
</template>
<script setup>
import { Cell as VanCell } from 'vant'
</script>Example: Cell with Click Handler
<template>
<van-cell
title="Cell Title"
value="Content"
is-link
@click="handleClick"
/>
</template>
<script setup>
import { Cell as VanCell, showToast } from 'vant'
const handleClick = () => {
showToast('Cell clicked')
}
</script>Example: Cell Groups
<template>
<van-cell-group>
<van-cell title="Cell 1" value="Content 1" />
<van-cell title="Cell 2" value="Content 2" />
<van-cell title="Cell 3" value="Content 3" />
</van-cell-group>
</template>
<script setup>
import { Cell as VanCell, CellGroup as VanCellGroup } from 'vant'
</script>Key Points
- Use
van-cellcomponent for cell display - Use
titleprop for cell title - Use
valueprop for cell value - Use
iconprop for cell icon - Use
is-linkprop for arrow indicator - Use
@clickfor click handlers - Use
van-cell-groupto group cells
Related local files
- API summary:
api/components.md - Nearby component pattern:
examples/components/button.md
Dialog | 对话框
官方文档入口: https://vant-ui.github.io/vant/#/zh-CN 官方对应章节: Dialog / 弹出框
Instructions
This example demonstrates how to use the Dialog component in Vant.
Key Concepts
- Basic Dialog
- Dialog with confirm
- Dialog with alert
- Dialog with custom content
- Dialog methods
Example: Basic Dialog
<template>
<van-button @click="show = true">Show Dialog</van-button>
<van-dialog
v-model:show="show"
title="Title"
message="This is a dialog message"
/>
</template>
<script setup>
import { ref } from 'vue'
import { Button as VanButton, Dialog as VanDialog } from 'vant'
const show = ref(false)
</script>Example: Dialog with Confirm
<template>
<van-button @click="showConfirm">Show Confirm</van-button>
</template>
<script setup>
import { Button as VanButton, showConfirmDialog } from 'vant'
const showConfirm = () => {
showConfirmDialog({
title: 'Confirm',
message: 'Are you sure?'
})
.then(() => {
console.log('Confirmed')
})
.catch(() => {
console.log('Cancelled')
})
}
</script>Example: Dialog with Alert
<template>
<van-button @click="showAlert">Show Alert</van-button>
</template>
<script setup>
import { Button as VanButton, showDialog } from 'vant'
const showAlert = () => {
showDialog({
title: 'Alert',
message: 'This is an alert'
})
}
</script>Example: Dialog with Custom Content
<template>
<van-button @click="show = true">Show Custom Dialog</van-button>
<van-dialog
v-model:show="show"
title="Custom Dialog"
show-cancel-button
@confirm="handleConfirm"
@cancel="show = false"
>
<van-field v-model="value" placeholder="Enter text" />
</van-dialog>
</template>
<script setup>
import { ref } from 'vue'
import { Button as VanButton, Dialog as VanDialog, Field as VanField, showToast } from 'vant'
const show = ref(false)
const value = ref('')
const handleConfirm = () => {
showToast(value.value)
show.value = false
}
</script>Key Points
- Use
van-dialogcomponent for dialog display - Use
v-model:showfor dialog visibility - Use
titleprop for dialog title - Use
messageprop for dialog message - Use
showConfirmDialog()for confirm dialogs - Use
showDialog()for alert dialogs - Use
@confirmand@cancelfor button handlers
Related local files
- API summary:
api/components.md - Feedback pattern:
examples/components/toast.md - Form-in-dialog pattern:
examples/components/form.md
Form | 表单
官方文档入口: https://vant-ui.github.io/vant/#/zh-CN 官方对应章节: Form / 表单
Instructions
This example demonstrates how to use Form components in Vant.
Key Concepts
- Form component setup
- Form validation
- Form fields
- Form submission
- Form layout
Example: Basic Form
<template>
<van-form @submit="onSubmit">
<van-cell-group inset>
<van-field
v-model="form.username"
name="username"
label="Username"
placeholder="Username"
:rules="[{ required: true, message: 'Please enter username' }]"
/>
<van-field
v-model="form.password"
type="password"
name="password"
label="Password"
placeholder="Password"
:rules="[{ required: true, message: 'Please enter password' }]"
/>
</van-cell-group>
<div style="margin: 16px;">
<van-button round block type="primary" native-type="submit">
Submit
</van-button>
</div>
</van-form>
</template>
<script setup>
import { ref } from 'vue'
import { Form as VanForm, Field as VanField, CellGroup as VanCellGroup, Button as VanButton } from 'vant'
const form = ref({
username: '',
password: ''
})
const onSubmit = (values) => {
console.log('Submit:', values)
}
</script>Example: Form with Validation
<template>
<van-form @submit="onSubmit" @failed="onFailed">
<van-cell-group inset>
<van-field
v-model="form.email"
name="email"
label="Email"
placeholder="Email"
:rules="emailRules"
/>
<van-field
v-model="form.password"
type="password"
name="password"
label="Password"
placeholder="Password"
:rules="passwordRules"
/>
</van-cell-group>
<div style="margin: 16px;">
<van-button round block type="primary" native-type="submit">
Submit
</van-button>
</div>
</van-form>
</template>
<script setup>
import { ref } from 'vue'
import { Form as VanForm, Field as VanField, CellGroup as VanCellGroup, Button as VanButton } from 'vant'
const form = ref({
email: '',
password: ''
})
const emailRules = [
{ required: true, message: 'Please enter email' },
{ pattern: /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/, message: 'Invalid email' }
]
const passwordRules = [
{ required: true, message: 'Please enter password' },
{ min: 6, message: 'Password must be at least 6 characters' }
]
const onSubmit = (values) => {
console.log('Submit:', values)
}
const onFailed = (errorInfo) => {
console.log('Failed:', errorInfo)
}
</script>Example: Form with Ref
<template>
<van-form ref="formRef">
<van-cell-group inset>
<van-field
v-model="form.username"
name="username"
label="Username"
:rules="[{ required: true, message: 'Please enter username' }]"
/>
</van-cell-group>
<div style="margin: 16px;">
<van-button type="primary" @click="submit">Submit</van-button>
<van-button @click="reset">Reset</van-button>
</div>
</van-form>
</template>
<script setup>
import { ref } from 'vue'
import { Form as VanForm, Field as VanField, CellGroup as VanCellGroup, Button as VanButton } from 'vant'
const formRef = ref(null)
const form = ref({
username: ''
})
const submit = async () => {
try {
await formRef.value.validate()
console.log('Form valid:', form.value)
} catch (error) {
console.log('Validation failed')
}
}
const reset = () => {
formRef.value.resetValidation()
form.value.username = ''
}
</script>Key Points
- Use
van-formcomponent to wrap form fields - Use
van-fieldfor form inputs - Use
:rulesprop for validation rules - Use
@submitfor form submission - Use
@failedfor validation failure - Use
refandvalidate()method for programmatic validation - Use
native-type="submit"for submit button
Related local files
- API summary:
api/components.md - Popup with form pattern:
examples/components/popup.md - Dialog with input pattern:
examples/components/dialog.md
Popup | 弹出层
官方文档入口: https://vant-ui.github.io/vant/#/zh-CN 官方对应章节: Popup / 弹出层
Instructions
This example demonstrates how to use the Popup component in Vant.
Key Concepts
- Basic Popup
- Popup positions (top, bottom, left, right, center)
- Popup with close button
- Popup with round corners
- Popup with overlay
Example: Basic Popup
<template>
<van-button @click="show = true">Show Popup</van-button>
<van-popup v-model:show="show" position="bottom">
<div style="padding: 20px;">Popup content</div>
</van-popup>
</template>
<script setup>
import { ref } from 'vue'
import { Button as VanButton, Popup as VanPopup } from 'vant'
const show = ref(false)
</script>Example: Popup Positions
<template>
<van-button @click="showTop = true">Top</van-button>
<van-button @click="showBottom = true">Bottom</van-button>
<van-button @click="showLeft = true">Left</van-button>
<van-button @click="showRight = true">Right</van-button>
<van-button @click="showCenter = true">Center</van-button>
<van-popup v-model:show="showTop" position="top">
<div style="padding: 20px;">Top popup</div>
</van-popup>
<van-popup v-model:show="showBottom" position="bottom">
<div style="padding: 20px;">Bottom popup</div>
</van-popup>
<van-popup v-model:show="showLeft" position="left">
<div style="padding: 20px;">Left popup</div>
</van-popup>
<van-popup v-model:show="showRight" position="right">
<div style="padding: 20px;">Right popup</div>
</van-popup>
<van-popup v-model:show="showCenter" position="center">
<div style="padding: 20px;">Center popup</div>
</van-popup>
</template>
<script setup>
import { ref } from 'vue'
import { Button as VanButton, Popup as VanPopup } from 'vant'
const showTop = ref(false)
const showBottom = ref(false)
const showLeft = ref(false)
const showRight = ref(false)
const showCenter = ref(false)
</script>Example: Popup with Round Corners
<template>
<van-button @click="show = true">Show Popup</van-button>
<van-popup
v-model:show="show"
position="bottom"
round
>
<div style="padding: 20px;">Popup with round corners</div>
</van-popup>
</template>
<script setup>
import { ref } from 'vue'
import { Button as VanButton, Popup as VanPopup } from 'vant'
const show = ref(false)
</script>Example: Popup with Close Button
<template>
<van-button @click="show = true">Show Popup</van-button>
<van-popup
v-model:show="show"
position="bottom"
closeable
close-icon-position="top-right"
>
<div style="padding: 20px;">Popup with close button</div>
</van-popup>
</template>
<script setup>
import { ref } from 'vue'
import { Button as VanButton, Popup as VanPopup } from 'vant'
const show = ref(false)
</script>Key Points
- Use
van-popupcomponent for popup display - Use
v-model:showfor popup visibility - Use
positionprop for popup position (top, bottom, left, right, center) - Use
roundprop for round corners - Use
closeableprop for close button - Use
close-icon-positionfor close button position - Popup supports overlay and click-to-close
Related local files
- API summary:
api/components.md - Dialog comparison:
examples/components/dialog.md
Toast | 提示
官方文档入口: https://vant-ui.github.io/vant/#/zh-CN 官方对应章节: Toast / 轻提示
Instructions
This example demonstrates how to use the Toast component in Vant.
Key Concepts
- Basic toast
- Toast types (success, fail, loading)
- Toast with custom message
- Toast duration
- Toast position
Example: Basic Toast
<template>
<van-button @click="showToast">Show Toast</van-button>
</template>
<script setup>
import { Button as VanButton, showToast } from 'vant'
const showToast = () => {
showToast('This is a toast message')
}
</script>Example: Toast Types
<template>
<van-button @click="showSuccess">Success</van-button>
<van-button @click="showFail">Fail</van-button>
<van-button @click="showLoading">Loading</van-button>
</template>
<script setup>
import { Button as VanButton, showToast, showSuccessToast, showFailToast, showLoadingToast } from 'vant'
const showSuccess = () => {
showSuccessToast('Success message')
}
const showFail = () => {
showFailToast('Fail message')
}
const showLoading = () => {
showLoadingToast('Loading...')
}
</script>Example: Toast with Options
<template>
<van-button @click="showCustomToast">Custom Toast</van-button>
</template>
<script setup>
import { Button as VanButton, showToast } from 'vant'
const showCustomToast = () => {
showToast({
type: 'success',
message: 'Custom toast',
duration: 3000,
position: 'top'
})
}
</script>Example: Using Toast Component
<template>
<van-button @click="show = true">Show Toast</van-button>
<van-toast v-model:show="show" message="Toast message" />
</template>
<script setup>
import { ref } from 'vue'
import { Button as VanButton, Toast as VanToast } from 'vant'
const show = ref(false)
</script>Key Points
- Use
showToast()function for toast messages - Use
showSuccessToast(),showFailToast(),showLoadingToast()for specific types - Use options object for custom configuration
- Use
durationprop for toast duration (milliseconds) - Use
positionprop for toast position (top, middle, bottom) - Use
van-toastcomponent for component-based usage - Toast is available globally via showToast function
Related local files
- API summary:
api/components.md - Dialog comparison:
examples/components/dialog.md
Basic Usage | 基本用法
官方文档入口: https://vant-ui.github.io/vant/#/zh-CN 官方对应章节: Quickstart / 快速开始
Instructions
This example demonstrates basic Vant component usage in Vue 3.
Key Concepts
- Using components
- Component props
- Component events
- Composition API
Example: Button Component
<template>
<van-button type="primary">Primary</van-button>
<van-button type="success">Success</van-button>
<van-button type="danger">Danger</van-button>
</template>
<script setup>
import { Button as VanButton } from 'vant'
</script>Example: Button with Events
<template>
<van-button type="primary" @click="handleClick">
Click Me
</van-button>
</template>
<script setup>
import { Button as VanButton, showToast } from 'vant'
const handleClick = () => {
showToast('Button clicked!')
}
</script>Example: Cell Component
<template>
<van-cell title="Cell Title" value="Content" />
<van-cell title="Cell Title" value="Content" is-link />
</template>
<script setup>
import { Cell as VanCell } from 'vant'
</script>Example: Multiple Components
<template>
<van-card
num="2"
price="2.00"
desc="Description"
title="Title"
thumb="https://img.yzcdn.cn/vant/cat.jpeg"
/>
<van-button type="primary" class="mt-3">Submit</van-button>
</template>
<script setup>
import { Card as VanCard, Button as VanButton } from 'vant'
</script>Key Points
- Import components from 'vant'
- Use component props to configure behavior
- Use @click for event handling
- Use Composition API with script setup
- Components are optimized for mobile
- Use showToast, showDialog for programmatic APIs
Installation | 安装
官方文档入口: https://vant-ui.github.io/vant/#/zh-CN 官方对应章节: Quickstart / 快速开始
Instructions
This example demonstrates how to install Vant and set it up in a Vue 3 project.
Key Concepts
- Installing Vant
- Importing styles
- Registering components
- Basic setup
Example: Installation
# Using npm
npm install vant
# Using yarn
yarn add vant
# Using pnpm
pnpm add vant
# Using bun
bun add vantExample: Import Styles
// Import CSS in your entry file (e.g., main.js or main.ts)
import 'vant/lib/index.css'Example: Full Import
// main.js
import { createApp } from 'vue'
import App from './App.vue'
import Vant from 'vant'
import 'vant/lib/index.css'
const app = createApp(App)
app.use(Vant)
app.mount('#app')Example: Tree-shaking Import
// main.js
import { createApp } from 'vue'
import App from './App.vue'
import { Button, Cell } from 'vant'
import 'vant/lib/index.css'
const app = createApp(App)
app.use(Button)
app.use(Cell)
app.mount('#app')Example: TypeScript Setup
// main.ts
import { createApp } from 'vue'
import App from './App.vue'
import Vant from 'vant'
import 'vant/lib/index.css'
const app = createApp(App)
app.use(Vant)
app.mount('#app')Example: Using unplugin-vue-components
// vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'
export default defineConfig({
plugins: [
vue(),
Components({
resolvers: [VantResolver()],
}),
],
})Key Points
- Install vant package
- Import Vant CSS in entry file
- Use app.use(Vant) for full import
- Or import components individually for tree-shaking
- Works with both JavaScript and TypeScript
- Use unplugin-vue-components for auto import
- Requires Vue 3
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Vant Vue 3 Official Mapping
This file maps the local skill content to the official Vant documentation entry points.
Official entry points
- Official website: https://vant-ui.github.io/
- Official guide: https://vant-ui.github.io/vant/#/zh-CN
Local coverage map
| Official area | Official section name | Local file | Coverage |
|---|---|---|---|
| Guide | Quickstart / 快速开始 | examples/getting-started/installation.md | Local setup instructions |
| Guide | Basic Usage / 基本用法 | examples/getting-started/basic-usage.md | Local starter usage |
| Guide | Project setup patterns | templates/project-setup.md | Local scaffold template |
| Component | Button / 按钮 | examples/components/button.md | Local example |
| Component | Cell / 单元格 | examples/components/cell.md | Local example |
| Component | Form / 表单 | examples/components/form.md | Local example |
| Component | Dialog / 弹出层中的对话交互 | examples/components/dialog.md | Local example |
| Component | Popup / 弹出层 | examples/components/popup.md | Local example |
| Component | Toast / 轻提示 | examples/components/toast.md | Local example |
| Global config | ConfigProvider | api/config-provider.md | Local API guidance |
| Theme | Theme customization / 主题定制 | examples/advanced/theme-customization.md | Local example |
| API summary | Common component APIs | api/components.md | Local summary |
Coverage boundary
This skill does not provide local example files for every Vant component.
Examples of components not covered locally include:
- Tabs
- Tabbar
- NavBar
- Icon
- Image
- Calendar
- Picker
- Grid
- Card
- Badge
- Loading
- ActionSheet
When the user requests one of these:
1. Use the official guide as the primary reference. 2. State clearly that the skill has no dedicated local example file for that component. 3. Follow the coding style already used in this skill:
- Vue 3
script setup - imports from
vant - mobile-first examples
- concise prop/event explanation
Navigation rule
Only reference local files that actually exist in:
examples/getting-started/examples/components/examples/advanced/api/templates/
Do not mention local files that are not present in the skill directory.
Component Template | 组件模板
使用时机:
- 用户要基于 Vant 快速搭一个新组件
- 已知要用 Vant 组件,但还没有明确的页面骨架
- 需要从通用结构开始,再替换成 Button / Cell / Form / Popup 等具体组件
关联文件:
api/components.mdexamples/components/button.mdexamples/components/cell.mdexamples/components/form.md
Basic Component Usage
<template>
<van-component-name
prop1="value1"
prop2="value2"
@event="handleEvent"
/>
</template>
<script setup>
import { ComponentName as VanComponentName } from 'vant'
const handleEvent = () => {
console.log('Event handled')
}
</script>Component with v-model
<template>
<van-field
v-model="value"
placeholder="Enter text"
/>
</template>
<script setup>
import { ref } from 'vue'
import { Field as VanField } from 'vant'
const value = ref('')
</script>Component in Form
<template>
<van-form @submit="onSubmit">
<van-field
v-model="form.field"
name="field"
label="Field"
:rules="[{ required: true, message: 'Please enter field' }]"
/>
<van-button type="primary" native-type="submit">Submit</van-button>
</van-form>
</template>
<script setup>
import { ref } from 'vue'
import { Form as VanForm, Field as VanField, Button as VanButton } from 'vant'
const form = ref({
field: ''
})
const onSubmit = (values) => {
console.log('Form submitted:', values)
}
</script>Usage notes
- 优先替换
ComponentName为当前真实需要的 Vant 组件 - 如果需要校验、提交、重置,优先参考
examples/components/form.md - 如果需要交互反馈,配合
showToast()或showDialog() - 如果需要全局主题变量,配合
api/config-provider.md
Project Setup Template | 项目设置模板
Basic Vue 3 + Vant Setup
// package.json
{
"dependencies": {
"vue": "^3.0.0",
"vant": "^4.0.0"
}
}// main.js
import { createApp } from 'vue'
import App from './App.vue'
import Vant from 'vant'
import 'vant/lib/index.css'
const app = createApp(App)
app.use(Vant)
app.mount('#app')<!-- App.vue -->
<template>
<van-config-provider :theme-vars="themeVars">
<router-view />
</van-config-provider>
</template>
<script setup>
import { ConfigProvider as VanConfigProvider } from 'vant'
const themeVars = {
primaryColor: '#07c160'
}
</script>With TypeScript
// main.ts
import { createApp } from 'vue'
import App from './App.vue'
import Vant from 'vant'
import 'vant/lib/index.css'
const app = createApp(App)
app.use(Vant)
app.mount('#app')<!-- App.vue -->
<template>
<van-config-provider :theme-vars="themeVars">
<router-view />
</van-config-provider>
</template>
<script setup lang="ts">
import { ConfigProvider as VanConfigProvider } from 'vant'
const themeVars = {
primaryColor: '#07c160'
}
</script>With Tree-shaking
// main.js
import { createApp } from 'vue'
import App from './App.vue'
import { Button, Cell, ConfigProvider } from 'vant'
import 'vant/lib/index.css'
const app = createApp(App)
app.use(Button)
app.use(Cell)
app.use(ConfigProvider)
app.mount('#app')With unplugin-vue-components
// vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'
export default defineConfig({
plugins: [
vue(),
Components({
resolvers: [VantResolver()],
}),
],
})