Skip to content

Commit

Permalink
docs: import quick start document (youzan#10945)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Aug 21, 2022
1 parent ec1d32d commit b4072ef
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 73 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ pnpm add vant

```js
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);
```

Expand Down
4 changes: 4 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,14 @@ pnpm add vant

```js
import { createApp } from 'vue';
// 1. 引入你需要的组件
import { Button } from 'vant';
// 2. 引入组件样式
import 'vant/lib/index.css';

const app = createApp();

// 3. 注册你需要的组件
app.use(Button);
```

Expand Down
64 changes: 29 additions & 35 deletions packages/vant/docs/markdown/quickstart.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pnpm add vant

### CDN

The easiest way to use Vant is to include a CDN link in the html file, after which you can access all components via the global variable `vant`.
The easiest way to use Vant is to include a CDN link in the HTML file, after which you can access all components via the global variable `vant`.

```html
<!-- import style -->
Expand Down Expand Up @@ -92,9 +92,28 @@ In the GUI, click on 'Dependencies' -> `Install Dependencies` and add `vant` to

## Usage

### Import on demand (recommended)
### Basic Usage

If you are using vite, webpack or vue-cli, please use [unplugin-vue-components](https://github.com/antfu/unplugin-vue-components).
The basic usage of Vant components;

```js
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);
```

> 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.
### Import on demand

If you are using vite, webpack or vue-cli, you can use [unplugin-vue-components](https://github.com/antfu/unplugin-vue-components), this plugin can help you to auto importing components and reduce CSS file size.

#### 1. Install Plugin

Expand Down Expand Up @@ -160,16 +179,14 @@ module.exports = {
};
```

#### 3. Import Components
#### 3. Using Components

Then you can import components from Vant:

```js
import { createApp } from 'vue';
import { Button } from 'vant';
Then you can using components from Vant in the template, the `unplugin-vue-components` will automatically import the corresponding Vant components.

const app = createApp();
app.use(Button);
```html
<template>
<van-button type="primary" />
</template>
```

#### 4. Style of Function Components
Expand All @@ -194,27 +211,4 @@ import { ImagePreview } from 'vant';
import 'vant/es/image-preview/style';
```

> Vant supports tree shaking by default, so you don't necessarily need the webpack plugin, if you can't accept the full import of css.
### Import all components (not recommended)

Import all components will **increase the bundle size**, so this is not recommended.

```js
import { createApp } from 'vue';
import Vant from 'vant';
import 'vant/lib/index.css';

const app = createApp();
app.use(Vant);
```

### Manually import (not recommended)

```js
// import script
import Button from 'vant/es/button/index';
// import style
// if the component does not have a style file, there is no need to import
import 'vant/es/button/style/index';
```
> Tip: "Full Import" and "On-demand Import" should not be used at the same time, otherwise it will lead to problems such as code duplication and style overrides.
70 changes: 32 additions & 38 deletions packages/vant/docs/markdown/quickstart.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pnpm add vant

### 通过 CDN 安装

使用 Vant 最简单的方法是直接在 html 文件中引入 CDN 链接,之后你可以通过全局变量 `vant` 访问到所有组件。
使用 Vant 最简单的方法是直接在 HTML 文件中引入 CDN 链接,之后你可以通过全局变量 `vant` 访问到所有组件。

```html
<!-- 引入样式文件 -->
Expand Down Expand Up @@ -93,9 +93,32 @@ pnpm add vant

## 引入组件

### 按需引入组件(推荐)
### 方法一. 基础用法

在基于 `vite``webpack``vue-cli` 的项目中使用 Vant 时,推荐安装 [unplugin-vue-components](https://github.com/antfu/unplugin-vue-components) 插件,它可以自动按需引入组件。
下面是使用 Vant 组件的基础用法示例:

```js
import { createApp } from 'vue';
// 1. 引入你需要的组件
import { Button } from 'vant';
// 2. 引入组件样式
import 'vant/lib/index.css';

const app = createApp();

// 3. 注册你需要的组件
app.use(Button);
```

Vant 支持多种组件注册方式,除了在 app 上全局注册组件,你也可以选择其他的方式,详见 [组件注册](#/zh-CN/advanced-usage#zu-jian-zhu-ce) 章节。

> 提示:Vant 默认支持 Tree Shaking,因此你不需要配置任何插件,通过 Tree Shaking 即可移除不需要的 JS 代码,但 CSS 样式无法通过这种方式优化,如果需要按需引入 CSS 样式,请参考下面的方法二。
### 方法二. 按需引入组件

在基于 `vite``webpack``vue-cli` 的项目中使用 Vant 时,可以使用 [unplugin-vue-components](https://github.com/antfu/unplugin-vue-components) 插件,它可以自动引入组件,并按需引入组件的样式。

相比于基础用法,这种方式可以按需引入组件的 CSS 样式,从而减少一部分代码体积。

#### 1. 安装插件

Expand Down Expand Up @@ -161,16 +184,14 @@ module.exports = {
};
```

#### 3. 引入组件
#### 3. 使用组件

完成以上两步,就可以直接使用 Vant 组件了:

```js
import { createApp } from 'vue';
import { Button } from 'vant';
完成以上两步,就可以直接在模板中使用 Vant 组件了,`unplugin-vue-components` 会解析模板并自动注册对应的组件。

const app = createApp();
app.use(Button);
```html
<template>
<van-button type="primary" />
</template>
```

#### 4. 引入函数组件的样式
Expand All @@ -195,31 +216,4 @@ import { ImagePreview } from 'vant';
import 'vant/es/image-preview/style';
```

> 注意:Vant 支持 Tree Shaking,因此你也可以不配置任何插件,通过 Tree Shaking 即可移除不需要的 JS 代码,但 CSS 无法通过这种方式优化。
### 导入所有组件(不推荐)

Vant 支持一次性导入所有组件,引入所有组件会**增加代码包体积**,因此不推荐这种做法。

```js
import { createApp } from 'vue';
import Vant from 'vant';
import 'vant/lib/index.css';

const app = createApp();
app.use(Vant);
```

> 提示:在单个项目中不应该同时使用「全量引入」和「按需引入」,否则会导致代码重复、样式错乱等问题。
### 手动按需引入组件(不推荐)

在不使用任何构建插件的情况下,可以手动引入需要使用的组件和样式。

```js
// 引入组件脚本
import Button from 'vant/es/button/index';
// 引入组件样式
// 若组件没有样式文件,则无须引入
import 'vant/es/button/style/index';
```

0 comments on commit b4072ef

Please sign in to comment.