docs: add full registration guide (#12628)

This commit is contained in:
neverland 2024-02-13 17:04:22 +08:00 committed by GitHub
parent 819b1cbd20
commit 3fcd1b95ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 0 deletions

View File

@ -25,6 +25,24 @@ app.use(Button);
app.component(Button.name, Button);
```
#### Full Registration
You can also globally register all Vant components at once:
```js
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);
```
> Note: Registering all components will introduce the code of all components, leading to larger bundle size.
#### Local Registration
```js

View File

@ -29,6 +29,24 @@ app.use(Button);
app.component(Button.name, Button);
```
#### 全量注册
你也可以在全局一次性注册所有 Vant 组件:
```js
import Vant from 'vant';
import { createApp } from 'vue';
const app = createApp();
app.use(Vant);
// Lazyload 指令需要单独进行注册
app.use(vant.Lazyload);
```
> 注意:注册所有组件会引入所有组件的代码,导致包体积增大。
#### 局部注册
局部注册后,你可以在当前组件中使用注册的 Vant 组件。