/*! For license information please see 9558.6787c2cd.js.LICENSE.txt */ (self.webpackChunk=self.webpackChunk||[]).push([["9558"],{30081:function(s,n,a){"use strict";a.r(n);var t=a("80681");let e=["innerHTML"];n.default={setup:()=>({html:""}),render:()=>((0,t.wg)(),(0,t.iD)("div",{class:"van-doc-markdown-body",innerHTML:'

Quickstart

\n

Install

\n

npm

\n

Using npm to install:

\n
# install latest Vant for Vue 3 project\nnpm i vant\n\n# install Vant 2 for Vue 2 project\nnpm i vant@latest-v2\n
\n

Using yarn, pnpm, or bun:

\n
# with yarn\nyarn add vant\n\n# with pnpm\npnpm add vant\n\n# with Bun\nbun add vant\n
\n

Using in a New Project

\n

If you need to create a new project, we recommend using Rsbuild, Vite or Nuxt framework.

\n

Rsbuild

\n

Rsbuild is a build tool based on Rspack, developed by the author of Vant, with first-class build speed and development experience, providing first-priority support for Vant.

\n

You can create a Rsbuild project with the following command:

\n
npm create rsbuild@latest\n
\n

Please visit the Rsbuild repository for more information.

\n

Example

\n

Here are the example projects provided by Vant official. You can clone these projects and copy the code.

\n\n

CDN

\n

If you only need to develop a simple HTML page, you can directly include the CDN links in the HTML file. After that, you can access all the components through the global variable vant.

\n
<!-- import style -->\n<link\n  rel="stylesheet"\n  href="https://fastly.jsdelivr.net/npm/vant@4/lib/index.css"\n/>\n\n<!-- import script -->\n<script src="https://fastly.jsdelivr.net/npm/vue@3"></script>\n<script src="https://fastly.jsdelivr.net/npm/vant@4/lib/vant.min.js"></script>\n\n<script>\n  // Render the Button component\n  const app = Vue.createApp({\n    template: `<van-button>Button</van-button>`,\n  });\n  app.use(vant);\n\n  // Register Lazyload directive\n  app.use(vant.Lazyload);\n\n  // Call function component\n  vant.showToast('Message');\n\n  app.mount('#app');\n</script>\n
\n

Free CDN

\n

You can use Vant through these free CDN services:

\n\n

Note: Free CDN is generally used for making prototypes or personal projects. It is not recommended to use free CDN in production environment.

\n

For enterprise developers, we recommend:

\n\n

Usage

\n

Basic Usage

\n

The basic usage of Vant components:

\n
import { createApp } from 'vue';\n// 1. Import the components you need\nimport { Button } from 'vant';\n// 2. Import the components style\nimport 'vant/lib/index.css';\n\nconst app = createApp();\n\n// 3. Register the components you need\napp.use(Button);\n
\n
\n

Tip: Vant supports Tree Shaking by default, so you don\'t need to configure any plugins, the unused JS code will be removed by Tree Shaking, but CSS styles cannot be optimized by it.

\n
\n

Import on demand

\n

If you are using Rsbuild, Vite, webpack or vue-cli, you can use unplugin-vue-components, this plugin can help you to auto importing components.

\n

Vant officially wrote an automatic import style parser @vant/auto-import-resolver based on unplugin-vue-components, both of which are used together.

\n

Compared with conventional usage, this method can introduce the CSS style of components on demand, thus reducing part of the code volume, but it will become more cumbersome to use. If the business\'s volume requirements for CSS are not particularly extreme, we recommend a simpler general usage.

\n

1. Install Plugin

\n
# with npm\nnpm i @vant/auto-import-resolver unplugin-vue-components unplugin-auto-import -D\n\n# with yarn\nyarn add @vant/auto-import-resolver unplugin-vue-components unplugin-auto-import -D\n\n# with pnpm\npnpm add @vant/auto-import-resolver unplugin-vue-components unplugin-auto-import -D\n\n# with Bun\nbun add @vant/auto-import-resolver unplugin-vue-components unplugin-auto-import -D\n
\n

2. Configure Plugin

\n

For Rsbuild based project\uFF0Cconfigure the plugin in the rsbuild.config.js file:

\n
import { defineConfig } from '@rsbuild/core';\nimport { pluginVue } from '@rsbuild/plugin-vue';\nimport AutoImport from 'unplugin-auto-import/rspack';\nimport Components from 'unplugin-vue-components/rspack';\nimport { VantResolver } from '@vant/auto-import-resolver';\n\nexport default defineConfig({\n  plugins: [pluginVue()],\n  tools: {\n    rspack: {\n      plugins: [\n        AutoImport({\n          resolvers: [VantResolver()],\n        }),\n        Components({\n          resolvers: [VantResolver()],\n        }),\n      ],\n    },\n  },\n});\n
\n

For Vite based project\uFF0Cconfigure the plugin in the vite.config.js file:

\n
import vue from '@vitejs/plugin-vue';\nimport AutoImport from 'unplugin-auto-import/vite';\nimport Components from 'unplugin-vue-components/vite';\nimport { VantResolver } from '@vant/auto-import-resolver';\n\nexport default {\n  plugins: [\n    vue(),\n    AutoImport({\n      resolvers: [VantResolver()],\n    }),\n    Components({\n      resolvers: [VantResolver()],\n    }),\n  ],\n};\n
\n

For vue-cli based project\uFF0Cconfigure the plugin in the vue.config.js file:

\n
const { VantResolver } = require('@vant/auto-import-resolver');\nconst AutoImport = require('unplugin-auto-import/webpack');\nconst Components = require('unplugin-vue-components/webpack');\n\nmodule.exports = {\n  configureWebpack: {\n    plugins: [\n      // When the version of unplugin-vue-components is less than 0.26.0:\n      AutoImport({ resolvers: [VantResolver()] }),\n      Components({ resolvers: [VantResolver()] }),\n      // when the unplugin-vue-components version is greater than or equal to 0.26.0:\n      AutoImport.default({ resolvers: [VantResolver()] }),\n      Components.default({ resolvers: [VantResolver()] }),\n    ],\n  },\n};\n
\n

For webpack based project\uFF0Cconfigure the plugin in the webpack.config.js file:

\n
const { VantResolver } = require('@vant/auto-import-resolver');\nconst AutoImport = require('unplugin-auto-import/webpack');\nconst Components = require('unplugin-vue-components/webpack');\n\nmodule.exports = {\n  plugins: [\n    // When the version of unplugin-vue-components is less than 0.26.0:\n    AutoImport({ resolvers: [VantResolver()] }),\n    Components({ resolvers: [VantResolver()] }),\n    // when the unplugin-vue-components version is greater than or equal to 0.26.0:\n    AutoImport.default({ resolvers: [VantResolver()] }),\n    Components.default({ resolvers: [VantResolver()] }),\n  ],\n};\n
\n

3. Using Components

\n

Then you can using components from Vant in the template, the unplugin-vue-components will automatically import the corresponding Vant components,@vant/auto-import-resolver The corresponding component style will be automatically introduced.

\n
<template>\n  <van-button type="primary" />\n</template>\n
\n

unplugin-auto-import will automatically import the corresponding Vant API and styles.

\n
<script>\nshowToast('No need to import showToast')\n</script>\n
\n

Tips

\n\n

With Frameworks

\n

Use Vant in Nuxt 3

\n

When using Vant in Nuxt 3, you can use vant-nuxt, this module can help you to auto importing components and reduce CSS file size.

\n

1. Install Module

\n
# with npm\nnpm i @vant/nuxt -D\n\n# with yarn\nyarn add @vant/nuxt -D\n\n# with pnpm\npnpm add @vant/nuxt -D\n\n# with Bun\nbun add @vant/nuxt -D\n
\n

2. Add Module

\n

add the module in the nuxt.config.js file:

\n
export default defineNuxtConfig({\n  modules: ['@vant/nuxt'],\n});\n
\n

3. Using Components

\n

Then you can using components from Vant in the template, Go to the Nuxt documentation to learn more.

\n
<template>\n  <van-button type="primary" @click="showToast('toast')">button</van-button>\n  <VanButton type="success" @click="showNotify('notify')">button</VanButton>\n  <LazyVanButton type="default">lazy button</LazyVanButton>\n</template>\n
\n
'},null,8,e))}}}]);