### Integrate Vant via CDN Source: https://github.com/youzan/vant/blob/main/packages/vant/docs/markdown/quickstart.en-US.md Example of including Vant in a standard HTML file via CDN links and initializing components globally. ```html ``` -------------------------------- ### Install Auto-Import Plugins Source: https://github.com/youzan/vant/blob/main/packages/vant/docs/markdown/quickstart.en-US.md Commands to install necessary plugins for automatic component and style importing in build tools. ```bash # with npm npm i @vant/auto-import-resolver unplugin-vue-components unplugin-auto-import -D # with yarn yarn add @vant/auto-import-resolver unplugin-vue-components unplugin-auto-import -D # with pnpm pnpm add @vant/auto-import-resolver unplugin-vue-components unplugin-auto-import -D # with Bun bun add @vant/auto-import-resolver unplugin-vue-components unplugin-auto-import -D ``` -------------------------------- ### Integrate Vant into Nuxt 3 Source: https://github.com/youzan/vant/blob/main/packages/vant/docs/markdown/quickstart.en-US.md Shows the installation and configuration steps for using Vant in a Nuxt 3 project via the @vant/nuxt module. ```bash npm i @vant/nuxt -D ``` ```js export default defineNuxtConfig({ modules: ['@vant/nuxt'], }); ``` ```html ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/youzan/vant/blob/main/packages/vant/docs/markdown/contribution.en-US.md Steps to clone the Vant repository, set up the pnpm package manager, install dependencies, and start local development. ```bash git clone git@github.com:vant-ui/vant.git corepack enable pnpm i pnpm dev ``` -------------------------------- ### Usage of Auto-Imported Vant Components Source: https://github.com/youzan/vant/blob/main/packages/vant/docs/markdown/quickstart.en-US.md Demonstrates how to use Vant components and APIs in Vue templates and scripts after configuring the auto-import plugins. ```html ``` -------------------------------- ### PickerGroup Setup Script Source: https://github.com/youzan/vant/blob/main/packages/vant/src/picker-group/README.zh-CN.md Provides the Vue 3 setup script for the PickerGroup controlled mode example. It includes refs for active tab, date, time, and handler functions for tab switching, confirmation, and cancellation. ```javascript import { ref } from 'vue'; import { showToast } from 'vant'; export default { setup() { const activeTab = ref(0); const currentDate = ref(['2022', '06', '01']); const currentTime = ref(['12', '00']); const setActiveTab = () => { activeTab.value = activeTab.value ? 0 : 1; }; const onConfirm = () => { showToast( `${currentDate.value.join('/')} ${currentTime.value.join(':')}`, ); }; const onCancel = () => { showToast('cancel'); }; return { minDate: new Date(2020, 0, 1), maxDate: new Date(2025, 5, 1), activeTab, currentDate, currentTime, setActiveTab, onConfirm, onCancel, }; }, }; ``` -------------------------------- ### Toast - Introduction and Installation Source: https://github.com/youzan/vant/blob/main/packages/vant/src/toast/README.zh-CN.md Introduction to the Toast component and how to install it globally in a Vue application. ```APIDOC ## Toast轻提示 ### 介绍 在页面中间弹出黑色半透明提示,用于消息通知、加载提示、操作结果提示等场景。 ### 引入 通过以下方式来全局注册组件,更多注册方式请参考[组件注册](#/zh-CN/advanced-usage#zu-jian-zhu-ce)。 ```js import { createApp } from 'vue'; import { Toast } from 'vant'; const app = createApp(); app.use(Toast); ``` ``` -------------------------------- ### Install @vant/popperjs with Bun Source: https://github.com/youzan/vant/blob/main/packages/vant-popperjs/README.md Use this command to install the package with Bun. ```shell bun add @vant/popperjs ``` -------------------------------- ### Install Vant Area Data via Bun Source: https://github.com/youzan/vant/blob/main/packages/vant-area-data/README.md Install the package using Bun. ```shell bun add @vant/area-data ``` -------------------------------- ### Install Vant with Yarn, pnpm, or Bun Source: https://github.com/youzan/vant/blob/main/packages/vant/docs/markdown/quickstart.zh-CN.md Alternative package managers for installing Vant. ```bash yarn add vant pnpm add vant bun add vant ``` -------------------------------- ### Signature Component Installation Source: https://github.com/youzan/vant/blob/main/packages/vant/src/signature/README.md Instructions on how to install and register the Vant Signature component globally. ```APIDOC ## Installation Register component globally via `app.use`, refer to [Component Registration](#/en-US/advanced-usage#zu-jian-zhu-ce) for more registration ways. ```js import { createApp } from 'vue'; import { Signature } from 'vant'; const app = createApp(); app.use(Signature); ``` ``` -------------------------------- ### Install @vant/use Package Source: https://github.com/youzan/vant/blob/main/packages/vant/docs/markdown/vant-use-intro.zh-CN.md Install the @vant/use package using your preferred package manager. This package contains Vant's composition APIs. ```shell # with npm npm i @vant/use # with yarn yarn add @vant/use # with pnpm pnpm add @vant/use # with Bun bun add @vant/use ``` -------------------------------- ### Install Vant 4 and Compatibility Package Source: https://github.com/youzan/vant/blob/main/packages/vant/docs/markdown/migrate-from-v3.en-US.md Commands to install Vant 4 and the @vant/compat package using various package managers. This is the first step in the migration process. ```bash # Install via npm npm add vant@^4 @vant/compat@^1 # Install via yarn yarn add vant@^4 @vant/compat@^1 # Install via pnpm pnpm add vant@^4 @vant/compat@^1 # Install via Bun bun add vant@^4 @vant/compat@^1 ``` -------------------------------- ### SwipeCell Installation Source: https://github.com/youzan/vant/blob/main/packages/vant/src/swipe-cell/README.md Instructions on how to install and register the SwipeCell component globally. ```APIDOC ## SwipeCell Installation Register component globally via `app.use`, refer to [Component Registration](#/en-US/advanced-usage#zu-jian-zhu-ce) for more registration ways. ```js import { createApp } from 'vue'; import { SwipeCell } from 'vant'; const app = createApp(); app.use(SwipeCell); ``` ``` -------------------------------- ### Install Vant Touch Emulator Source: https://github.com/youzan/vant/blob/main/packages/vant/docs/markdown/advanced-usage.zh-CN.md Install the `@vant/touch-emulator` package using npm. This package enables mouse event simulation for touch devices, allowing Vant components to work on desktop browsers. ```bash # 安装模块 npm i @vant/touch-emulator -S ``` -------------------------------- ### Install @vant/popperjs with yarn Source: https://github.com/youzan/vant/blob/main/packages/vant-popperjs/README.md Use this command to install the package with yarn. ```shell yarn add @vant/popperjs ``` -------------------------------- ### Install Vant Area Data via pnpm Source: https://github.com/youzan/vant/blob/main/packages/vant-area-data/README.md Install the package using pnpm. ```shell pnpm add @vant/area-data ``` -------------------------------- ### Install @vant/popperjs with npm Source: https://github.com/youzan/vant/blob/main/packages/vant-popperjs/README.md Use this command to install the package with npm. ```shell npm i @vant/popperjs ``` -------------------------------- ### Use Vant Button in ``` -------------------------------- ### Install Vant Icons with Bun Source: https://github.com/youzan/vant/blob/main/packages/vant-icons/README.md Use this command to install Vant Icons if you are using Bun as your package manager. ```shell # with Bun bun add @vant/icons ``` -------------------------------- ### Install Plugins for On-Demand CSS Import Source: https://github.com/youzan/vant/blob/main/packages/vant/docs/markdown/quickstart.zh-CN.md Install necessary plugins for automatic component import and CSS styling with Vant, compatible with Rsbuild, Vite, webpack, or vue-cli. ```bash # 通过 npm 安装 npm i @vant/auto-import-resolver unplugin-vue-components unplugin-auto-import -D # 通过 yarn 安装 yarn add @vant/auto-import-resolver unplugin-vue-components unplugin-auto-import -D # 通过 pnpm 安装 pnpm add @vant/auto-import-resolver unplugin-vue-components unplugin-auto-import -D # 通过 bun 安装 bun add @vant/auto-import-resolver unplugin-vue-components unplugin-auto-import -D ``` -------------------------------- ### Install Vant Area Data via npm Source: https://github.com/youzan/vant/blob/main/packages/vant-area-data/README.md Install the package using npm. ```shell npm i @vant/area-data ``` -------------------------------- ### Install @vant/popperjs with pnpm Source: https://github.com/youzan/vant/blob/main/packages/vant-popperjs/README.md Use this command to install the package with pnpm. ```shell pnpm add @vant/popperjs ``` -------------------------------- ### Install Stylelint Dependencies Source: https://github.com/youzan/vant/blob/main/packages/vant/docs/markdown/release-note-v4.zh-CN.md Vant Cli 5.0 no longer installs stylelint and its configuration by default. Install them manually if needed. ```bash npm add stylelint@13 @vant/stylelint-config ``` -------------------------------- ### Install Vant Area Data via yarn Source: https://github.com/youzan/vant/blob/main/packages/vant-area-data/README.md Install the package using yarn. ```shell yarn add @vant/area-data ``` -------------------------------- ### Install Vant with npm Source: https://github.com/youzan/vant/blob/main/packages/vant/docs/markdown/quickstart.zh-CN.md Use npm to install the latest Vant for Vue 3 projects or Vant 2 for Vue 2 projects. ```bash npm i vant npm i vant@latest-v2 ``` -------------------------------- ### Layout Installation Source: https://github.com/youzan/vant/blob/main/packages/vant/src/col/README.md Install and register the Row and Col components globally using app.use. ```APIDOC ## Installation ### Description Register the Row and Col components globally using `app.use`. ### Code ```javascript import { createApp } from 'vue'; import { Col, Row } from 'vant'; const app = createApp(); app.use(Col); app.use(Row); ``` ``` -------------------------------- ### Install @vant/compat package Source: https://github.com/youzan/vant/blob/main/packages/vant-compat/README.md Commands to install the @vant/compat compatibility layer using various package managers including npm, yarn, pnpm, and bun. ```shell # with npm npm i @vant/compat # with yarn yarn add @vant/compat # with pnpm pnpm add @vant/compat # with Bun bun add @vant/compat ``` -------------------------------- ### Installation and Basic Usage Source: https://github.com/youzan/vant/blob/main/packages/vant/src/steps/README.zh-CN.md How to import and use the Steps and Step components in a Vue application. ```APIDOC ## Installation and Basic Usage ### Introduction Used to display the various stages of an operation process, allowing users to understand their current position in the overall flow. ### Importing Components Globally register the components using the following method. For more registration methods, please refer to [Component Registration](#/zh-CN/advanced-usage#zu-jian-zhu-ce). ```js import { createApp } from 'vue'; import { Step, Steps } from 'vant'; const app = createApp(); app.use(Step); app.use(Steps); ``` ## Code Demonstration ### Basic Usage The `active` property indicates the index of the current step, starting from 0. ```html Buyer Places Order Seller Accepts Order Buyer Picks Up Goods Transaction Complete ``` ```js import { ref } from 'vue'; export default { setup() { const active = ref(1); return { active }; }, }; ``` ``` -------------------------------- ### Get Uploader Instance Type Source: https://github.com/youzan/vant/blob/main/packages/vant/src/uploader/README.zh-CN.md Demonstrates how to get the type for the Uploader component instance. This is useful for referencing the component instance in your Vue setup. ```typescript import { ref } from 'vue'; import type { UploaderInstance } from 'vant'; const uploaderRef = ref(); uploaderRef.value?.chooseFile(); ``` -------------------------------- ### Vue Component Setup for ImagePreview Source: https://github.com/youzan/vant/blob/main/packages/vant/src/image-preview/README.zh-CN.md Provides the necessary Vue 3 Composition API setup for the `van-image-preview` component, including reactive state for visibility, current index, and image sources. ```javascript import { ref } from 'vue'; export default { setup() { const show = ref(false); const index = ref(0); const images = [ 'https://fastly.jsdelivr.net/npm/@vant/assets/apple-1.jpeg', 'https://fastly.jsdelivr.net/npm/@vant/assets/apple-2.jpeg', ]; const onChange = (newIndex) => { index.value = newIndex; }; return { show, index, images, onChange, }; }, }; ``` -------------------------------- ### Ellipsis at Start - TextEllipsis Source: https://github.com/youzan/vant/blob/main/packages/vant/src/text-ellipsis/README.zh-CN.md Control the ellipsis position to appear at the beginning of the text using `position="start"`. This example truncates after 1 row. ```html ``` ```javascript export default { setup() { const text = '那一天我二十一岁,在我一生的黄金时代。我有好多奢望。我想爱,想吃,还想在一瞬间变成天上半明半暗的云。后来我才知道,生活就是个缓慢受锤的过程,人一天天老下去,奢望也一天天消失,最后变得像挨了锤的牛一样。可是我过二十一岁生日时没有预见到这一点。我觉得自己会永远生猛下去,什么也锤不了我。'; return { text }; }, }; ``` -------------------------------- ### Installation and Usage Source: https://github.com/youzan/vant/blob/main/packages/vant/src/watermark/README.zh-CN.md Instructions on how to import and register the Vant Watermark component globally. ```APIDOC ## Installation and Usage ### Introduction Add specific text or patterns as watermarks on the page to prevent information theft. Please upgrade `vant` to version >= 4.2.0 to use this component. ### Import Register the component globally as follows. For more registration methods, please refer to [Component Registration](#/zh-CN/advanced-usage#zu-jian-zhu-ce). ```js import { createApp } from 'vue'; import { Watermark } from 'vant'; const app = createApp(); app.use(Watermark); ``` ``` -------------------------------- ### Install Vant Rate Component Globally Source: https://github.com/youzan/vant/blob/main/packages/vant/src/rate/README.md Demonstrates how to install the Vant Rate component globally using app.use in a Vue application. This is a common setup for making components readily available throughout the app. ```javascript import { createApp } from 'vue'; import { Rate } from 'vant'; const app = createApp(); app.use(Rate); ``` -------------------------------- ### Quickstart Component Registration Source: https://github.com/youzan/vant/blob/main/README.md Demonstrates how to import specific Vant components and their corresponding styles into a Vue 3 application, followed by global registration. ```javascript import { createApp } from 'vue'; // 1. Import the components you need import { Button } from 'vant'; // 2. Import the components style import 'vant/lib/index.css'; const app = createApp(); // 3. Register the components you need app.use(Button); ``` -------------------------------- ### Basic Usage Example Source: https://github.com/youzan/vant/blob/main/packages/vant/docs/markdown/use-relation.zh-CN.md Demonstrates how to establish a parent-child relationship using `useChildren` in the parent and `useParent` in the child. ```APIDOC ## Basic Usage ### Parent Component (`useChildren`) In the parent component, use `useChildren` to associate child components: ```js import { ref } from 'vue'; import { useChildren } from '@vant/use'; const RELATION_KEY = Symbol('my-relation'); export default { setup() { const { linkChildren } = useChildren(RELATION_KEY); const count = ref(0); const add = () => { count.value++; }; // Provide data and methods to child components linkChildren({ add, count }); }, }; ``` ### Child Component (`useParent`) In the child component, use `useParent` to get the data and methods provided by the parent: ```js import { useParent } from '@vant/use'; export default { setup() { const { parent } = useParent(RELATION_KEY); // Call methods and access data provided by the parent if (parent) { parent.add(); console.log(parent.count.value); // -> 1 } }, }; ``` ``` -------------------------------- ### Using RollingTextInstance Type in Vue Source: https://github.com/youzan/vant/blob/main/packages/vant/src/rolling-text/README.zh-CN.md Type a template ref with `RollingTextInstance` to get proper autocompletion and type checking when accessing component methods like `start`. ```typescript import { ref } from 'vue'; import type { RollingTextInstance } from 'vant'; const rollingTextRef = ref(); rollingTextRef.value?.start(); ``` -------------------------------- ### Create Vant CLI Project Source: https://github.com/youzan/vant/blob/main/packages/vant-cli/README.md Run this command to initialize a new Vant CLI project. ```bash yarn create vant-cli-app ``` -------------------------------- ### Vant ActionBar with Icon Badges (Vue.js) Source: https://github.com/youzan/vant/blob/main/packages/vant/src/action-bar/README.md This example demonstrates how to use the `dot` and `badge` props on ActionBarIcon components to display notification badges. It includes examples for a simple red dot and a badge with a numerical count. Assumes Vant is installed and components are registered. ```html ``` -------------------------------- ### Vue Component Setup for ImagePreview with Video Slot Source: https://github.com/youzan/vant/blob/main/packages/vant/src/image-preview/README.zh-CN.md Vue 3 Composition API setup for using the `van-image-preview` component with a custom `image` slot that renders a video player. Includes reactive state for visibility and image sources. ```javascript import { ref } from 'vue'; export default { setup() { const show = ref(false); const images = [ 'https://www.w3school.com.cn/i/movie.ogg', 'https://www.w3school.com.cn/i/movie.ogg', 'https://www.w3school.com.cn/i/movie.ogg', ]; return { show, images, }; }, }; ``` -------------------------------- ### Vue Setup for Manual RollingText Control Source: https://github.com/youzan/vant/blob/main/packages/vant/src/rolling-text/README.zh-CN.md Implement manual control functions for starting and resetting the RollingText animation. Access the component instance using a template ref. ```javascript import { ref } from 'vue'; export default { setup() { const rollingTextRef = ref(null); const start = () => { rollingTextRef.value.start(); }; const reset = () => { rollingTextRef.value.reset(); }; return { rollingTextRef, start, reset }; }, }; ``` -------------------------------- ### Configure Circle Appearance and Position Source: https://github.com/youzan/vant/blob/main/packages/vant/src/circle/README.md Examples of customizing the Circle component using props for layer color, direction, size, and starting position. ```html ``` -------------------------------- ### Basic Usage of useScrollParent Source: https://github.com/youzan/vant/blob/main/packages/vant/docs/markdown/use-scroll-parent.zh-CN.md This example demonstrates how to use the useScrollParent hook to get the scrollable parent of a div element and attach a scroll event listener to it. Ensure the target element is rendered in the DOM. ```html
``` ```javascript import { ref, watch } from 'vue'; import { useScrollParent, useEventListener } from '@vant/use'; export default { setup() { const root = ref(); const scrollParent = useScrollParent(root); useEventListener( 'scroll', () => { console.log('scroll'); }, { target: scrollParent }, ); return { root }; }, }; ``` -------------------------------- ### Vant Tabs with Swipeable and Sticky Element Source: https://github.com/youzan/vant/blob/main/packages/vant/src/tab/README.zh-CN.md When `swipeable` or `animated` is enabled on `van-tabs`, content elements wrapped in `van-sticky` may not display as expected due to transform positioning. This example demonstrates the setup where the issue occurs. ```html sticky button ``` -------------------------------- ### Configure Auto-Import Plugins for Build Tools Source: https://github.com/youzan/vant/blob/main/packages/vant/docs/markdown/quickstart.en-US.md Configures Vant auto-import resolvers for Rsbuild, Vite, Vue-CLI, and Webpack. These configurations use unplugin-auto-import and unplugin-vue-components to automate component registration and style loading. ```js import { defineConfig } from '@rsbuild/core'; import { pluginVue } from '@rsbuild/plugin-vue'; import AutoImport from 'unplugin-auto-import/rspack'; import Components from 'unplugin-vue-components/rspack'; import { VantResolver } from '@vant/auto-import-resolver'; export default defineConfig({ plugins: [pluginVue()], tools: { rspack: { plugins: [ AutoImport({ resolvers: [VantResolver()] }), Components({ resolvers: [VantResolver()] }), ], }, }, }); ``` ```js import vue from '@vitejs/plugin-vue'; import AutoImport from 'unplugin-auto-import/vite'; import Components from 'unplugin-vue-components/vite'; import { VantResolver } from '@vant/auto-import-resolver'; export default { plugins: [ vue(), AutoImport({ resolvers: [VantResolver()] }), Components({ resolvers: [VantResolver()] }), ], }; ``` ```js const { VantResolver } = require('@vant/auto-import-resolver'); const AutoImport = require('unplugin-auto-import/webpack'); const Components = require('unplugin-vue-components/webpack'); module.exports = { configureWebpack: { plugins: [ AutoImport.default({ resolvers: [VantResolver()] }), Components.default({ resolvers: [VantResolver()] }), ], }, }; ``` -------------------------------- ### Enable PC Browser Touch Emulation Source: https://github.com/youzan/vant/blob/main/packages/vant/docs/markdown/advanced-usage.en-US.md Installs and imports the touch emulator module to convert mouse events into touch events, allowing mobile-first Vant components to function correctly on desktop browsers. ```bash npm i @vant/touch-emulator -S ``` ```javascript import '@vant/touch-emulator'; ``` -------------------------------- ### Vant Collapse toggleAll Method Examples Source: https://github.com/youzan/vant/blob/main/packages/vant/src/collapse/README.zh-CN.md Demonstrates how to use the toggleAll method to control the expanded state of all collapse items. Supports options like skipping disabled items. ```javascript import { ref } from 'vue'; import type { CollapseInstance } from 'vant'; const collapseRef = ref(); // 全部切换 collapseRef.value?.toggleAll(); // 全部展开 collapseRef.value?.toggleAll(true); // 全部收起 collapseRef.value?.toggleAll(false); // 全部全部切换,并跳过禁用的复选框 collapseRef.value?.toggleAll({ skipDisabled: true, }); // 全部选中,并跳过禁用的复选框 collapseRef.value?.toggleAll({ expanded: true, skipDisabled: true, }); ``` -------------------------------- ### Basic Usage Source: https://github.com/youzan/vant/blob/main/packages/vant/src/loading/README.zh-CN.md Demonstrates the basic usage of the Loading component with default settings. ```APIDOC ## Basic Usage ### Description Displays a circular loading indicator. ### Method N/A (Component Usage) ### Endpoint N/A (Component Usage) ### Request Example ```html ``` ### Response Example (No direct response, renders a loading spinner) ``` -------------------------------- ### Vant ActionBar with Custom Button Colors (Vue.js) Source: https://github.com/youzan/vant/blob/main/packages/vant/src/action-bar/README.md This example demonstrates how to customize the background color of ActionBarButton components using the `color` prop. It supports single colors and linear gradients. Assumes Vant is installed and components are registered. ```html ``` -------------------------------- ### Basic Usage Source: https://github.com/youzan/vant/blob/main/packages/vant/src/address-list/README.zh-CN.md Demonstrates the basic implementation of the AddressList component with sample data. ```APIDOC ## Basic Usage ### Introduction Displays a list of addresses. ### Import Globally register the component using the following method. For more registration methods, please refer to [Component Registration](#/zh-CN/advanced-usage#zu-jian-zhu-ce). ```js import { createApp } from 'vue'; import { AddressList } from 'vant'; const app = createApp(); app.use(AddressList); ``` ### Code Demonstration ```html ``` ```js import { ref } from 'vue'; import { showToast } from 'vant'; export default { setup() { const chosenAddressId = ref('1'); const list = [ { id: '1', name: '张三', tel: '13000000000', address: '浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室', isDefault: true, }, { id: '2', name: '李四', tel: '1310000000', address: '浙江省杭州市拱墅区莫干山路 50 号', }, ]; const disabledList = [ { id: '3', name: '王五', tel: '1320000000', address: '浙江省杭州市滨江区江南大道 15 号', }, ]; const onAdd = () => showToast('新增地址'); const onEdit = (item, index) => showToast('编辑地址:' + index); return { list, onAdd, onEdit, disabledList, chosenAddressId, }; }, }; ``` ``` -------------------------------- ### Register Vant Components in Vue Source: https://github.com/youzan/vant/blob/main/packages/vant/docs/markdown/advanced-usage.en-US.md Demonstrates various ways to register Vant components, including global registration via app.use, full library registration, local component registration, and usage within script setup or JSX. ```javascript import { Button } from 'vant'; import { createApp } from 'vue'; const app = createApp(); // Method 1. via app.use app.use(Button); // Method 2. Register via app.component app.component(Button.name, Button); ``` ```javascript import Vant from 'vant'; import { createApp } from 'vue'; const app = createApp(); app.use(Vant); // The Lazyload directive needs to be registered separately app.use(vant.Lazyload); ``` ```javascript import { Button } from 'vant'; export default { components: { [Button.name]: Button, }, }; ``` ```xml ``` ```jsx import { Button } from 'vant'; export default { render() { return