[Improvement] Reorganize document (#1066)

This commit is contained in:
neverland
2018-05-15 10:39:01 +08:00
committed by GitHub
parent b1142fd862
commit e8aad7246c
124 changed files with 181 additions and 186 deletions
+89
View File
@@ -0,0 +1,89 @@
## Actionsheet
### Install
``` javascript
import { Actionsheet } from 'vant';
Vue.use(Actionsheet);
```
### Usage
#### Basic Usage
Use `actions` prop to set options of actionsheet.
```html
<van-actionsheet v-model="show" :actions="actions" />
```
```javascript
export default {
data() {
return {
show: false,
actions: [
{
name: 'Option',
callback: this.onClick
},
{
name: 'Option',
description: 'Description'
},
{
name: 'Option',
loading: true
}
]
};
},
methods: {
onClick(item) {
Toast(item.name);
}
}
}
```
#### Actionsheet with cancel button
```html
<van-actionsheet v-model="show" :actions="actions" cancel-text="Cancel" />
```
#### Actionsheet with title
Actionsheet will get another style if there is a `title` prop.
```html
<van-actionsheet v-model="show" title="Title">
<p>Content</p>
</van-actionsheet>
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| actions | Options | `Array` | `[]` |
| title | Title | `String` | - |
| cancel-text | Text of cancel button | `String` | - |
| overlay | Whether to show overlay | `Boolean` | - |
| close-on-click-overlay | Whether to close when click overlay | `Boolean` | - |
| get-container | Return the mount node for actionsheet | `() => HTMLElement` | - |
### Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| cancel | Triggered when cancel click | - |
### Data struct of actions
| key | Description |
|-----------|-----------|
| name | Title |
| subname | Subtitle |
| className | className for the option |
| loading | Whether to be loading status |
| callback | Triggered when click option |
+94
View File
@@ -0,0 +1,94 @@
## Actionsheet 行动按钮
### 使用指南
``` javascript
import { Actionsheet } from 'vant';
Vue.use(Actionsheet);
```
### 代码演示
#### 基础用法
需要传入一个`actions`的数组,数组的每一项是一个对象,对象属性见文档下方表格。
```html
<van-actionsheet v-model="show" :actions="actions" />
```
```javascript
export default {
data() {
return {
show: false,
actions: [
{
name: '选项',
callback: this.onClick
},
{
name: '选项',
subname: '描述信息'
},
{
name: '选项',
loading: true
}
]
};
},
methods: {
onClick(item) {
Toast(item.name);
}
}
}
```
#### 带取消按钮的 Actionsheet
如果传入了`cancelText`属性,且不为空,则会在下方显示一个取消按钮,点击会将当前`Actionsheet`关闭。
```html
<van-actionsheet v-model="show" :actions="actions" cancel-text="取消" />
```
#### 带标题的 Actionsheet
如果传入了`title`属性,且不为空,则另外一种样式的`Actionsheet`,里面内容需要自定义。
```html
<van-actionsheet v-model="show" title="支持以下配送方式">
<p>一些内容</p>
</van-actionsheet>
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| actions | 行动按钮数组 | `Array` | `[]` |
| title | 标题 | `String` | - |
| cancel-text | 取消按钮文案 | `String` | - |
| overlay | 是否显示遮罩 | `Boolean` | - |
| close-on-click-overlay | 点击遮罩是否关闭`Actionsheet` | `Boolean` | - |
| get-container | 指定挂载的 HTML 节点 | `() => HTMLElement` | - |
### Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| cancel | 取消按钮点击时触发 | - |
### actions
`API`中的`actions`为一个对象数组,数组中的每一个对象配置每一列,每一列有以下`key`
| key | 说明 |
|-----------|-----------|
| name | 标题 |
| subname | 二级标题 |
| className | 为对应列添加特殊的`class` |
| loading | 是否是`loading`状态 |
| callback | 点击时的回调。该回调接受一个参数,参数为当前点击`action`的对象信息 |
+116
View File
@@ -0,0 +1,116 @@
## AddressEdit
### Install
``` javascript
import { AddressEdit } from 'vant';
Vue.use(AddressEdit);
```
### Usage
#### Basic Usage
```html
<van-address-edit
:area-list="areaList"
show-postal
show-delete
show-set-default
show-search-result
:search-result="searchResult"
@save="onSave"
@delete="onDelete"
@change-detail="onChangeDetail"
/>
```
```javascript
export default {
data() {
return {
areaList,
searchResult: []
}
},
methods: {
onSave() {
Toast('save');
},
onDelete() {
Toast('delete');
},
onChangeDetail(val) {
if (val) {
this.searchResult = [{
name: '黄龙万科中心',
address: '杭州市西湖区'
}];
} else {
this.searchResult = [];
}
}
}
}
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| area-list | Area List | `Object` | - |
| address-info | Address Info | `Object` | `{}` |
| search-result | Address search result | `Array` | `[]` |
| show-postal | Whether to show postal field | `Boolean` | `false` |
| show-delete | Whether to show delete button | `Boolean` | `false` |
| show-set-default | Whether to show default address switch | `Boolean` | `false` |
| show-search-result | Whether to show address search result | `Boolean` | `false` |
| is-saving | Whether to show save button loading status | `Boolean` | `false` |
| is-deleting | Whether to show delete button loading status | `Boolean` | `false` |
| tel-validator | The method to validate tel | `(tel: string) => boolean` | - |
### Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| save | Triggered when click save button | contentform content |
| focus | Triggered when focus field | key: filed name |
| delete | Triggered when confirm delete | contentform content |
| cancel-delete | Triggered when cancel delete | contentform content |
| select-search | Triggered when select search result | value: search content |
| change-area | Triggered when change area | values: area values |
| change-detail | Triggered when address detail changed | value: address detail |
### Slot
| Name | Description |
|-----------|-----------|
| - | Custom content below postal |
### Data Structure
#### addressInfo Data Structure
| key | Description | Type |
|-----------|-----------|-----------|
| id | Address Id | `String | Number` |
| name | Name | `String` |
| tel | Phone | `String` |
| province | Province | `String` |
| city | City | `String` |
| county | County | `String` |
| address_detail | Detailed Address | `String` |
| area_code | Area code | `String` |
| postal_code | Postal code | `String` |
| is_default | Is default address | `Boolean` |
#### searchResult Data Structure
| key | Description | Type |
|-----------|-----------|-----------|
| name | Name | `String` |
| address | Address | `String` |
#### Area Data Structure
Please refer to [Area](#/en-US/area) component。
+115
View File
@@ -0,0 +1,115 @@
## AddressEdit 地址编辑
### 使用指南
``` javascript
import { AddressEdit } from 'vant';
Vue.use(AddressEdit);
```
### 代码演示
#### 基础用法
```html
<van-address-edit
:area-list="areaList"
show-postal
show-delete
show-set-default
show-search-result
:search-result="searchResult"
@save="onSave"
@delete="onDelete"
@change-detail="onChangeDetail"
/>
```
```javascript
export default {
data() {
return {
areaList,
searchResult: []
}
},
methods: {
onSave() {
Toast('save');
},
onDelete() {
Toast('delete');
},
onChangeDetail(val) {
if (val) {
this.searchResult = [{
name: '黄龙万科中心',
address: '杭州市西湖区'
}];
} else {
this.searchResult = [];
}
}
}
}
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| area-list | 地区列表 | `Object` | - |
| address-info | 收货人信息 | `Object` | `{}` |
| search-result | 详细地址搜索结果 | `Array` | `[]` |
| show-postal | 是否显示邮政编码 | `Boolean` | `false` |
| show-delete | 是否显示删除按钮 | `Boolean` | `false` |
| show-set-default | 是否显示默认地址栏 | `Boolean` | `false` |
| show-search-result | 是否显示搜索结果 | `Boolean` | `false` |
| is-saving | 是否显示保存按钮加载动画 | `Boolean` | `false` |
| is-deleting | 是否显示删除按钮加载动画 | `Boolean` | `false` |
| tel-validator | 手机号格式校验函数 | `(tel: string) => boolean` | - |
### Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| save | 点击保存按钮时触发 | content:表单内容 |
| focus | 输入框聚焦时触发 | key: 聚焦的输入框对应的 key |
| delete | 确认删除地址时触发 | content:表单内容 |
| cancel-delete | 取消删除地址时触发 | content:表单内容 |
| select-search | 选中搜索结果时触发 | value: 搜索结果 |
| change-area | 修改收件地区时触发 | values: 地区信息 |
| change-detail | 修改详细地址时触发 | value: 详细地址内容 |
### Slot
| 名称 | 说明 |
|-----------|-----------|
| - | 在邮政编码下方插入内容 |
### 数据格式
#### addressInfo 数据格式
| key | 说明 | 类型 |
|-----------|-----------|-----------|
| id | 每条地址的唯一标识 | `String | Number` |
| name | 收货人姓名 | `String` |
| tel | 收货人手机号 | `String` |
| province | 省份 | `String` |
| city | 城市 | `String` |
| county | 区县 | `String` |
| address_detail | 详细地址 | `String` |
| area_code | 地区编码,通过省市区选择获取 | `String` |
| postal_code | 邮政编码 | `String` |
| is_default | 是否为默认地址 | `Boolean` |
#### searchResult 数据格式
| key | 说明 | 类型 |
|-----------|-----------|-----------|
| name | 地名 | `String` |
| address | 详细地址 | `String` |
#### 省市县列表数据格式
请参考 [Area](#/zh-CN/area) 组件。
+79
View File
@@ -0,0 +1,79 @@
## AddressList
### Install
``` javascript
import { AddressList } from 'vant';
Vue.use(AddressList);
```
### Usage
#### Basic Usage
```html
<van-address-list
v-model="chosenAddressId"
:list="list"
@add="onAdd"
@edit="onEdit"
/>
```
```javascript
export default {
data() {
return {
chosenAddressId: '1',
list: [
{
id: '1',
name: 'John Snow',
tel: '13000000000',
address: 'Somewhere'
},
{
id: '2',
name: 'Ned Stark',
tel: '1310000000',
address: 'Somewhere'
}
]
}
},
methods: {
onAdd() {
Toast('Add');
},
onEdit(item, index) {
Toast('Edit:' + index);
}
}
}
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| v-model | Id of chosen address | String | - |
| list | Address list | Array | `[]` |
| add-button-text | Add button text | String | `Add new address` |
### Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| add | Triggered when click add button | - |
| edit | Triggered when click edit button | item: address objectindex |
| select | Triggered when select address | item: address objectindex |
### Address Data Structure
| key | Description | Type |
|-----------|-----------|-----------|
| id | Id | `String | Number` |
| name | Name | `String` |
| tel | Phone | `String` |
| address | Address | `String` |
+80
View File
@@ -0,0 +1,80 @@
## AddressList 地址列表
### 使用指南
``` javascript
import { AddressList } from 'vant';
Vue.use(AddressList);
```
### 代码演示
#### 基础用法
```html
<van-address-list
v-model="chosenAddressId"
:list="list"
@add="onAdd"
@edit="onEdit"
/>
```
```javascript
export default {
data() {
return {
chosenAddressId: '1',
list: [
{
id: '1',
name: '张三',
tel: '13000000000',
address: '浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室'
},
{
id: '2',
name: '李四',
tel: '1310000000',
address: '浙江省杭州市拱墅区莫干山路 50 号'
}
]
}
},
methods: {
onAdd() {
Toast('新增收货地址');
},
onEdit(item, index) {
Toast('编辑收货地址:' + index);
}
}
}
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| v-model | 当前选中地址的 id | String | - |
| list | 地址列表 | Array | `[]` |
| add-button-text | 底部按钮文字 | String | `新增收货地址` |
### Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| add | 点击新增按钮时触发 | - |
| edit | 点击编辑按钮时触发 | item: 当前地址对象,index: 索引 |
| select | 切换选中的地址时触发 | item: 当前地址对象,index: 索引 |
### 数据格式
#### 地址列表字段说明
| key | 说明 | 类型 |
|-----------|-----------|-----------|
| id | 每条地址的唯一标识 | `String | Number` |
| name | 收货人姓名 | `String` |
| tel | 收货人手机号 | `String` |
| address | 收货地址 | `String` |
+108
View File
@@ -0,0 +1,108 @@
## Area
The Picker component is usually used with [Popup](#/en-US/popup) Component.
### Install
``` javascript
import { Area } from 'vant';
Vue.use(Area);
```
### Usage
#### Basic Usage
To initailize `Area` component, `area-list` property is required. Data structure will be introduced later.
```html
<van-area :area-list="areaList" />
```
#### Initial Value
To have a selected valuesimply pass the `code` of target area to `value` property.
```html
<van-area :area-list="areaList" value="110101" />
```
#### Columns Number
`columns-num` property is used to config number of columns to be displayed. This component has 3 columns corresponding to a 3 level picker by default.
Set `columns-num` with 2, you'll have a 2 level picker.
```html
<van-area :area-list="areaList" :columns-num="2" title="Title" />
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| value | the `code` of selected area | `String` | - |
| title | Toolbar title | `String` | - |
| area-list | Area data | `Object` | - |
| columns-num | level of picker | `String | Number` | `3` |
| item-height | Option height | `Number` | `44` |
| loading | Whether to show loading prompt | `Boolean` | `false` |
| visible-item-count | Count of visible columns | `Number` | `5` |
### Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| confirm | triggers when clicking the confirm button | an array |
| cancel | triggers when clicking the cancel button | - |
| change | Triggered when current option changed | Picker instance, current valuescolumn index |
### Data Structure
#### areaList
An object contains three properties: `province_list`, `city_list` and `county_list`.
Each property is a simple key-value object, key is a 6-bit code of the area of which first two bits stand for the province or state, middle two bits are used as city code and the last two are district code, value is the name of the area. If the code stands for an area that has sub-areas, lower bits of it will be filled with 0.
Example of `AreaList`
```javascript
{
province_list: {
110000: 'Beijing',
330000: 'Zhejiang Province'
},
city_list: {
110100: 'Beijing City',
330100: 'Hangzhou',
},
county_list: {
110101: 'Dongcheng District',
110102: 'Xicheng District',
110105: 'Chaoyang District',
110106: 'Fengtai District'
330105: 'Gongshu District',
330106: 'Xihu District',
// ....
}
}
```
All code of China: [Area.json](https://github.com/youzan/vant/blob/dev/packages/area/demo/area-en.js)
#### argument of callback function confirm
An array contains selected area objects.
`code` - code of selected area, `name` - name of selected area
```javascript
[{
code: '330000',
name: 'Zhejiang Province'
}, {
code: '330100',
name: 'Hangzhou'
},{
code: '330105',
name: 'Xihu District'
}]
```
+118
View File
@@ -0,0 +1,118 @@
## Area 省市县选择组件
省市县选择组件通常与 [弹出层](#/zh-CN/popup) 组件配合使用
### 使用指南
```javascript
import { Area } from 'vant';
Vue.use(Area);
```
### 代码演示
#### 基础用法
要初始化一个`Area`组件,你需要传入一个`area-list`属性,数据格式具体可看下面数据格式章节
```html
<van-area :area-list="areaList" />
```
#### 选中省市县
如果想选中某个省市县,需要传入一个`value`属性,绑定对应的省市县`code`
```html
<van-area :area-list="areaList" value="110101" />
```
#### 配置显示列
可以通过`columns-num`属性配置省市县显示的列数,默认情况下会显示省市县,当你设置为`2`,则只会显示省市选择
```html
<van-area :area-list="areaList" :columns-num="2" title="标题" />
```
### API
| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| value | 当前选中的省市区`code` | `String` | - |
| title | 顶部栏标题 | `String` | - |
| area-list | 省市县数据,格式见下方 | `Object` | - |
| columns-num | 省市县显示列数,3-省市县,2-省市,1-省 | `String | Number` | `3` |
| loading | 是否显示加载状态 | `Boolean` | `false` |
| item-height | 选项高度 | `Number` | `44` |
| visible-item-count | 可见的选项个数 | `Number` | `5` |
### Event
| 事件 | 说明 | 回调参数 |
| --- | --- | --- |
| confirm | 点击右上方完成按钮 | 一个数组参数,具体格式看下方数据格式章节 |
| cancel | 点击取消按钮时 | - |
| change | 选项改变时触发 | Picker 实例,所有列选中值,当前列对应的索引 |
### 数据格式
#### 省市县列表数据格式
整体是一个 Object,包含 `province_list`, `city_list`, `county_list` 三个 key。
每项以省市区编码作为 key,省市区名字作为 value。编码为 6 位数字,前两位代表省份,中间两位代表城市,后两位代表区县,以 0 补足 6 位。如北京编码为 `11`,以零补足 6 位,为 `110000`
`AreaList`具体格式如下:
```javascript
{
province_list: {
110000: '北京市',
120000: '天津市'
},
city_list: {
110100: '北京市',
110200: '县',
120100: '天津市',
120200: '县'
},
county_list: {
110101: '东城区',
110102: '西城区',
110105: '朝阳区',
110106: '丰台区'
120101: '和平区',
120102: '河东区',
120103: '河西区',
120104: '南开区',
120105: '河北区',
// ....
}
}
```
完整数据见 [Area.json](https://github.com/youzan/vant/blob/dev/packages/area/demo/area.js)
#### 点击完成时返回的数据格式
返回的数据整体为一个数组,数组内包含 `columnsNum` 个数据, 每个数据对应一列选项中被选中的数据。
`code` 代表被选中的地区编码, `name` 代表被选中的地区名称
```javascript
[
{
code: '110000',
name: '北京市'
},
{
code: '110100',
name: '北京市'
},
{
code: '110101',
name: '东城区'
}
];
```
+51
View File
@@ -0,0 +1,51 @@
## Badge
### Install
``` javascript
import { Badge, BadgeGroup } from 'vant';
Vue.use(Badge);
Vue.use(BadgeGroup);
```
### Usage
#### Basic Usage
Use `active-key` prop to set index of chosen 'badge'
```html
<van-badge-group :active-key="activeKey">
<van-badge title="Title" @click="onClick" />
<van-badge title="Title" @click="onClick" info="8" />
<van-badge title="Title" @click="onClick" info="99" />
<van-badge title="Title" @click="onClick" info="199" />
</van-badge-group>
```
``` javascript
export default {
data() {
return {
activeKey: 0
};
},
methods: {
onClick(key) {
this.activeKey = key;
}
}
};
```
### BadgeGroup API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| active-key | Index of chosen badge | `String | Number` | `0` |
### Badge API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| title | Content | `String` | `''` |
| info | Info Message | `String | Number` | `''` |
| url | Link | `String` | - |
+52
View File
@@ -0,0 +1,52 @@
## Badge 徽章
### 使用指南
``` javascript
import { Badge, BadgeGroup } from 'vant';
Vue.use(Badge);
Vue.use(BadgeGroup);
```
### 代码演示
#### 基础用法
通过在`van-badge-group`上设置`active-key`属性来控制选中的`badge`
```html
<van-badge-group :active-key="activeKey">
<van-badge title="标签名称" @click="onClick" />
<van-badge title="标签名称" @click="onClick" info="8" />
<van-badge title="标签名称" @click="onClick" info="99" />
<van-badge title="标签名称" @click="onClick" info="199" />
</van-badge-group>
```
``` javascript
export default {
data() {
return {
activeKey: 0
};
},
methods: {
onClick(key) {
this.activeKey = key;
}
}
};
```
### BadgeGroup API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| active-key | 选中`badge`的索引 | `String | Number` | `0` |
### Badge API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| title | 内容 | `String` | `''` |
| info | 提示消息 | `String | Number` | `''` |
| url | 跳转链接 | `String` | - |
+84
View File
@@ -0,0 +1,84 @@
## Button
### Install
``` javascript
import { Button } from 'vant';
Vue.use(Button);
```
### Usage
#### Type
```html
<van-button type="default">Default</van-button>
<van-button type="primary">Primary</van-button>
<van-button type="danger">Danger</van-button>
```
#### Size
```html
<van-button size="large">Large</van-button>
<van-button size="normal">Normal</van-button>
<van-button size="small">Small</van-button>
<van-button size="mini">Mini</van-button>
```
#### Disabled
```html
<van-button disabled>Diabled</van-button>
```
#### Loading
```html
<van-button loading />
<van-button loading type="primary" />
```
#### Custom Tag
Use `tag` prop to custom button tag
```html
<van-button tag="a" href="https://www.youzan.com" target="_blank">
Button
</van-button>
```
#### Action Button
```html
<van-button type="primary" bottom-action>Button</van-button>
<van-row>
<van-col span="12">
<van-button bottom-action>Button</van-button>
</van-col>
<van-col span="12">
<van-button type="primary" bottom-action>Button</van-button>
</van-col>
</van-row>
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| type | Can be set to `default` `primary` `danger` | `String` | `default` |
| size | Can be set to `normal` `large` `small` `mini` | `String` | `normal` |
| text | Text | `String` | - |
| tag | Tag | `String` | `button` |
| native-type | Native Type Attribute | `String` | `''` |
| disabled | Whether disable button | `Boolean` | `false` |
| loading | Whether show loading status | `Boolean` | `false` |
| block | Whether to set display block | `Boolean` | `false` |
| bottom-action | Whether to be action button | `Boolean` | `false` |
### Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| click | Triggered when click button and not disabled or loading | - |
+88
View File
@@ -0,0 +1,88 @@
## Button 按钮
### 使用指南
``` javascript
import { Button } from 'vant';
Vue.use(Button);
```
### 代码演示
#### 按钮类型
支持`default`、`primary`、`danger`三种类型,默认为`default`
```html
<van-button type="default">默认按钮</van-button>
<van-button type="primary">主要按钮</van-button>
<van-button type="danger">危险按钮</van-button>
```
#### 按钮尺寸
支持`large`、`normal`、`small`、`mini`四种尺寸,默认为`normal`
```html
<van-button size="large">大号按钮</van-button>
<van-button size="normal">普通按钮</van-button>
<van-button size="small">小型按钮</van-button>
<van-button size="mini">迷你按钮</van-button>
```
#### 禁用状态
通过`disabled`属性来禁用按钮,此时按钮不可点击
```html
<van-button disabled>禁用状态</van-button>
```
#### 加载状态
```html
<van-button loading />
<van-button loading type="primary" />
```
#### 自定义按钮标签
按钮标签默认为`button`,可以使用`tag`属性来修改按钮标签
```html
<van-button tag="a" href="https://www.youzan.com" target="_blank">
按钮
</van-button>
```
#### 页面底部操作按钮
```html
<van-button type="primary" bottom-action>按钮</van-button>
<van-row>
<van-col span="12">
<van-button bottom-action>按钮</van-button>
</van-col>
<van-col span="12">
<van-button type="primary" bottom-action>按钮</van-button>
</van-col>
</van-row>
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| type | 按钮类型,可选值为 `default` `primary` `danger` | `String` | `default` |
| size | 按钮尺寸,可选值为 `normal` `large` `small` `mini` | `String` | `normal` |
| text | 按钮文字 | `String` | - |
| tag | 按钮 HTML 标签 | `String` | `button` |
| native-type | 按钮类型(原生) | `String` | - |
| disabled | 是否禁用 | `Boolean` | `false` |
| loading | 是否显示为加载状态 | `Boolean` | `false` |
| block | 是否为块级元素 | `Boolean` | `false` |
| bottom-action | 是否为底部行动按钮 | `Boolean` | `false` |
### Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| click | 点击按钮且按钮状态不为加载或禁用时触发 | - |
+62
View File
@@ -0,0 +1,62 @@
## Card
### Install
``` javascript
import { Card } from 'vant';
Vue.use(Card);
```
### Usage
#### Basic Usage
```html
<van-card
title="Title"
desc="Description"
num="2"
price="2.00"
:thumb="imageURL"
/>
```
#### Advanced Usage
Use `slot` to custom content.
```html
<van-card
title="Title"
desc="Description"
num="2"
price="2.00"
:thumb="imageURL"
>
<div slot="footer">
<van-button size="mini">Button</van-button>
<van-button size="mini">Button</van-button>
</div>
</van-card>
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| thumb | Left thumb | `String` | - |
| title | Title | `String` | - |
| desc | Description | `String` | - |
| num | Number of goods | `String | Number` | - |
| price | Price of goods | `String | Number` | - |
| centered | Whether content vertical centered | `String` | `false` |
| currency | Currency symbol | `String` | `¥` |
### Slot
| name | Description |
|-----------|-----------|
| title | Custom title |
| desc | Custom description |
| tags | Custom tags |
| thumb | Custom thumb |
| footer | Custom footer |
+62
View File
@@ -0,0 +1,62 @@
## Card 卡片
### 使用指南
``` javascript
import { Card } from 'vant';
Vue.use(Card);
```
### 代码演示
#### 基础用法
```html
<van-card
title="标题"
desc="描述"
num="2"
price="2.00"
:thumb="imageURL"
/>
```
#### 高级用法
可以通过具名`slot`添加定制内容
```html
<van-card
title="标题"
desc="描述"
num="2"
price="2.00"
:thumb="imageURL"
>
<div slot="footer">
<van-button size="mini">按钮</van-button>
<van-button size="mini">按钮</van-button>
</div>
</van-card>
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| thumb | 左侧图片 | `String` | - |
| title | 标题 | `String` | - |
| desc | 描述 | `String` | - |
| num | 商品数量 | `String | Number` | - |
| price | 商品价格 | `String | Number` | - |
| centered | 内容是否垂直居中 | `String` | `false` |
| currency | 货币符号 | `String` | `¥` |
### Slot
| 名称 | 说明 |
|-----------|-----------|
| title | 自定义标题 |
| desc | 自定义描述 |
| tags | 自定义 tags |
| thumb | 自定义 thumb |
| footer | 自定义 footer |
+79
View File
@@ -0,0 +1,79 @@
## CellSwipe
### Install
``` javascript
import { CellSwipe } from 'vant';
Vue.use(CellSwipe);
```
### Usage
#### Basic Usage
```html
<van-cell-swipe :right-width="65" :left-width="65">
<span slot="left">Select</span>
<van-cell-group>
<van-cell title="Cell" value="Cell Content" />
</van-cell-group>
<span slot="right">Delete</span>
</van-cell-swipe>
```
#### Async close
```html
<van-cell-swipe :right-width="65" :left-width="65" :on-close="onClose">
<span slot="left">Select</span>
<van-cell-group>
<van-cell title="Cell" value="Cell Content" />
</van-cell-group>
<span slot="right">Delete</span>
</van-cell-swipe>
```
```js
export default {
methods: {
onClose(clickPosition, instance) {
switch (clickPosition) {
case 'left':
case 'cell':
case 'outside':
instance.close();
break;
case 'right':
Dialog.confirm({
message: 'Are you sure to delete?'
}).then(() => {
instance.close();
});
break;
}
}
}
}
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| left-width | Width of the left scrollable area | `Number` | `0` |
| right-width | Width of the right scrollable area | `Number` | `0` |
| on-close | Callback function before close | `Function` | - |
### Slot
| name | Description |
|-----------|-----------|
| - | custom content |
| left | content of left scrollable area |
| right | content of right scrollabe area |
### onClose Params
| Argument | Type | Description |
|-----------|-----------|-----------|
| clickPosition | `String` | Click positon (`left` `right` `cell` `outside`) |
| instance | `Object` | CellSwipe instance with a close method |
+79
View File
@@ -0,0 +1,79 @@
## CellSwipe 滑动单元格
### 使用指南
``` javascript
import { CellSwipe } from 'vant';
Vue.use(CellSwipe);
```
### 代码演示
#### 基础用法
```html
<van-cell-swipe :right-width="65" :left-width="65">
<span slot="left">选择</span>
<van-cell-group>
<van-cell title="单元格" value="内容" />
</van-cell-group>
<span slot="right">删除</span>
</van-cell-swipe>
```
#### 异步关闭
```html
<van-cell-swipe :right-width="65" :left-width="65" :on-close="onClose">
<span slot="left">选择</span>
<van-cell-group>
<van-cell title="单元格" value="内容" />
</van-cell-group>
<span slot="right">删除</span>
</van-cell-swipe>
```
```js
export default {
methods: {
onClose(clickPosition, instance) {
switch (clickPosition) {
case 'left':
case 'cell':
case 'outside':
instance.close();
break;
case 'right':
Dialog.confirm({
message: '确定删除吗?'
}).then(() => {
instance.close();
});
break;
}
}
}
}
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| left-width | 左侧滑动区域宽度 | `Number` | `0` |
| right-width | 右侧滑动区域宽度 | `Number` | `0` |
| on-close | 关闭时的回调函数 | `Function` | - |
### Slot
| 名称 | 说明 |
|-----------|-----------|
| - | 自定义显示内容 |
| left | 左侧滑动内容 |
| right | 右侧滑动内容 |
### onClose 参数
| 参数 | 类型 | 说明 |
|-----------|-----------|-----------|
| clickPosition | `String` | 关闭时的点击位置 (`left` `right` `cell` `outside`) |
| instance | `Object` | CellSwipe 实例,挂载有 close 方法 |
+99
View File
@@ -0,0 +1,99 @@
## Cell
### Install
``` javascript
import { Cell, CellGroup } from 'vant';
Vue.use(Cell).use(CellGroup);
```
### Usage
#### Basic Usage
```html
<van-cell-group>
<van-cell title="Cell title" value="Content" />
<van-cell title="Cell title" value="Content" label="Description" />
</van-cell-group>
```
#### Value only
```html
<van-cell-group>
<van-cell value="Content" />
</van-cell-group>
```
#### Left Icon
```html
<van-cell-group>
<van-cell title="Cell title" icon="location" />
</van-cell-group>
```
#### Link
```html
<van-cell-group>
<van-cell title="Cell title" is-link />
<van-cell title="Cell title" is-link value="Content" />
</van-cell-group>
```
#### Advanced Usage
```html
<van-cell-group>
<van-cell value="Content" icon="shop" is-link>
<template slot="title">
<span class="van-cell-text">Cell title</span>
<van-tag type="danger">Tag</van-tag>
</template>
</van-cell>
<van-cell title="Cell title" icon="location" is-link />
<van-cell title="Cell title">
<van-icon slot="right-icon" name="search" class="van-cell__right-icon" />
</van-cell>
</van-cell-group>
```
### CellGroup API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| border | Whether to show outer border | `Boolean` | `true` |
### Cell API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| icon | Left Icon | `String` | - |
| title | Title | `String` | - |
| value | Right text | `String` | - |
| label | Description below the title | `String` | - |
| border | Whether to show inner border | `Boolean` | `true` |
| center | Whether to center content vertically | `Boolean` | `true` |
| url | Link URL | `String` | - |
| to | Target route of the link, same as to of `vue-router` | `String | Object` | - |
| replace | If true, the navigation will not leave a history record | `String` | `false` |
| clickable | Whether to show click feedback when clicked | `Boolean` | `false` |
| is-link | Whether to show link icon | `Boolean` | `false` |
| required | Whether to show required mark | `Boolean` | `false` |
### Cell Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| click | Triggered when click cell | - |
### Cell Slot
| name | Description |
|-----------|-----------|
| - | Default slot |
| icon | Custom icon |
| title | Custom title |
| right-icon | Custom right icon |
+106
View File
@@ -0,0 +1,106 @@
## Cell 单元格
### 使用指南
``` javascript
import { Cell, CellGroup } from 'vant';
Vue.use(Cell).use(CellGroup);
```
### 代码演示
#### 基础用法
将`van-cell-group`组件看成一个容器即可
```html
<van-cell-group>
<van-cell title="单元格" value="内容" />
<van-cell title="单元格" value="内容" label="描述信息" />
</van-cell-group>
```
#### 只设置value
只设置`value`时会向左对齐
```html
<van-cell-group>
<van-cell value="内容" />
</van-cell-group>
```
#### 展示图标
通过`icon`属性在标题左侧展示图标
```html
<van-cell-group>
<van-cell title="单元格" icon="location" />
</van-cell-group>
```
#### 展示箭头
传入`is-link`属性则会在右侧显示箭头
```html
<van-cell-group>
<van-cell title="单元格" is-link />
<van-cell title="单元格" is-link value="内容" />
</van-cell-group>
```
#### 高级用法
如以上用法不能满足你的需求,可以使用对应的`slot`来自定义显示的内容
```html
<van-cell-group>
<van-cell value="内容" icon="shop" is-link>
<template slot="title">
<span class="van-cell-text">单元格</span>
<van-tag type="danger">标签</van-tag>
</template>
</van-cell>
<van-cell title="单元格" icon="location" is-link />
<van-cell title="单元格">
<van-icon slot="right-icon" name="search" class="van-cell__right-icon" />
</van-cell>
</van-cell-group>
```
### CellGroup API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| border | 是否显示外边框 | `Boolean` | `true` |
### Cell API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| icon | 左侧图标,可选值见 Icon 组件 | `String` | - |
| title | 左侧标题 | `String` | - |
| value | 右侧内容 | `String` | - |
| label | 标题下方的描述信息 | `String` | - |
| border | 是否显示内边框 | `Boolean` | `true` |
| center | 是否使内容垂直居中 | `Boolean` | `false` |
| url | 跳转链接 | `String` | - |
| to | 路由跳转对象,同 `vue-router` 的 to | `String | Object` | - |
| replace | 跳转时是否替换当前 history | `String` | `false` |
| clickable | 是否开启点击反馈 | `Boolean` | `false` |
| is-link | 是否展示右侧箭头并开启点击反馈 | `Boolean` | `false` |
| required | 是否显示表单必填星号 | `Boolean` | `false` |
### Cell Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| click | 点击 cell 时触发 | - |
### Cell Slot
| 名称 | 说明 |
|-----------|-----------|
| - | 自定义显示内容 |
| icon | 自定义`icon` |
| title | 自定义`title` |
| right-icon | 自定义右侧按钮,默认是`arrow` |
+120
View File
@@ -0,0 +1,120 @@
## Checkbox
### Install
``` javascript
import { Checkbox, CheckboxGroup } from 'vant';
Vue.use(Checkbox).use(CheckboxGroup);
```
### Usage
#### Basic Usage
```html
<van-checkbox v-model="checked">Checkbox</van-checkbox>
```
```javascript
export default {
data() {
return {
checked: true
};
}
};
```
#### Disabled
```html
<van-checkbox v-model="checked" disabled>Checkbox</van-checkbox>
```
#### Disable Label click event
```html
<van-checkbox v-model="checked" label-disabled>Checkbox</van-checkbox>
```
#### Checkbox Group
When Checkboxes are inside a CheckboxGroup, the checked checkboxes's name is an array and bound with CheckboxGroup by v-model.
```html
<van-checkbox-group v-model="result">
<van-checkbox
v-for="(item, index) in list"
:key="item"
:name="item"
>
Checkbox {{ item }}
</van-checkbox>
</van-checkbox-group>
```
```javascript
export default {
data() {
return {
list: ['a', 'b', 'c'],
result: ['a', 'b']
};
}
};
```
#### Maximum amount of checked options
```html
<van-checkbox-group v-model="result" :max="2">
<van-checkbox
v-for="(item, index) in list"
:name="item"
:key="item"
>
Checkbox {{ item }}
</van-checkbox>
</van-checkbox-group>
```
#### Inside a Cell
```html
<van-checkbox-group v-model="result">
<van-cell-group>
<van-cell v-for="item in list" :title="`Checkbox ${item}`" :key="item">
<van-checkbox :name="item" />
</van-cell>
</van-cell-group>
</van-checkbox-group>
```
### Checkbox API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| v-model | Check status | `Boolean` | `false` |
| name | Checkbox name | `any` | - |
| disabled | Diable checkbox | `Boolean` | `false` |
| label-disabled | Whether to disable label click | `Boolean` | `false` |
| shape | Can be set to `round` `square` | `String` | `round` |
### CheckboxGroup API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| v-model | Names of all checked checkboxes | `Array` | - |
| disabled | Disable all checkboxes | `Boolean` | `false` |
| max | Maximum amount of checked options | `Number` | `0`(Unlimited) |
### Checkbox Event
| Event | Description | Parameters |
|-----------|-----------|-----------|
| change | Triggered when value changed | current value |
### CheckboxGroup Event
| Event | Description | Parameters |
|-----------|-----------|-----------|
| change | Triggered when value changed | current value |
+124
View File
@@ -0,0 +1,124 @@
## Checkbox 复选框
### 使用指南
``` javascript
import { Checkbox, CheckboxGroup } from 'vant';
Vue.use(Checkbox).use(CheckboxGroup);
```
### 代码演示
#### 基础用法
通过`v-model`绑定 checkbox 的勾选状态
```html
<van-checkbox v-model="checked">复选框</van-checkbox>
```
```javascript
export default {
data() {
return {
checked: true
};
}
};
```
#### 禁用状态
```html
<van-checkbox v-model="checked" disabled>复选框</van-checkbox>
```
#### 禁用内容部分点击事件
```html
<van-checkbox v-model="checked" label-disabled>复选框</van-checkbox>
```
#### Checkbox 组
需要与`van-checkbox-group`一起使用,选中值是一个数组,通过`v-model`绑定在`van-checkbox-group`上,数组中的项即为选中的`Checkbox`的`name`属性设置的值
```html
<van-checkbox-group v-model="result">
<van-checkbox
v-for="(item, index) in list"
:key="item"
:name="item"
>
复选框 {{ item }}
</van-checkbox>
</van-checkbox-group>
```
```javascript
export default {
data() {
return {
list: ['a', 'b', 'c'],
result: ['a', 'b']
};
}
};
```
#### 设置最大可选数
```html
<van-checkbox-group v-model="result" :max="2">
<van-checkbox
v-for="(item, index) in list"
:key="item"
:name="item"
>
复选框 {{ item }}
</van-checkbox>
</van-checkbox-group>
```
#### 与 Cell 组件一起使用
此时你需要再引入`Cell`和`CellGroup`组件
```html
<van-checkbox-group v-model="result">
<van-cell-group>
<van-cell v-for="item in list" :title="`复选框 ${item}`" :key="item">
<van-checkbox :name="item" />
</van-cell>
</van-cell-group>
</van-checkbox-group>
```
### Checkbox API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| v-model | 是否为选中状态 | `Boolean` | `false` |
| name | 标识 Checkbox 名称 | `any` | - |
| disabled | 是否禁用单选框 | `Boolean` | `false` |
| label-disabled | 是否禁用单选框内容点击 | `Boolean` | `false` |
| shape | 形状,可选值为 `round` `square` | `String` | `round` |
### CheckboxGroup API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| v-model | 所有选中项的 name | `Array` | - |
| disabled | 是否禁用所有单选框 | `Boolean` | `false` |
| max | 设置最大可选数 | `Number` | `0`(无限制) |
### Checkbox Event
| 事件名称 | 说明 | 回调参数 |
|-----------|-----------|-----------|
| change | 当绑定值变化时触发的事件 | 当前组件的值 |
### CheckboxGroup Event
| 事件名称 | 说明 | 回调参数 |
|-----------|-----------|-----------|
| change | 当绑定值变化时触发的事件 | 当前组件的值 |
+75
View File
@@ -0,0 +1,75 @@
## Circle
### Install
``` javascript
import { Circle } from 'vant';
Vue.use(Circle);
```
### Usage
#### Basic Usage
```html
<van-circle
v-model="currentRate"
:rate="30"
:speed="100"
:text="text"
/>
```
``` javascript
export default {
data() {
return {
currentRate: 0
};
},
computed: {
text() {
return this.currentRate.toFixed(0) + '%'
}
}
};
```
#### Custom style
```html
<van-circle
v-model="currentRate"
color="#13ce66"
fill="#fff"
size="120px"
layer-color="#eee"
:text="text"
:rate="rate"
:speed="100"
:clockwise="false"
:stroke-width="60"
/>
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| v-model | Current rate | `Number` | - |
| rate | Target rate | `Number` | `100` |
| size | Circle size | `String` | `100px` |
| color | Progress bar color | `String` | `#38f` |
| layer-color | Layer color | `String` | `#fff` |
| fill | Fill color | `String` | `none` |
| speed | Animate speedrate/s| `Number` | - |
| text | Text | `String` | - |
| stroke-width | Stroke width | `Number` | `40` |
| clockwise | Is clockwise | `Boolean` | `true` |
### Cell Slot
| name | Description |
|-----------|-----------|
| - | custom text content |
+76
View File
@@ -0,0 +1,76 @@
## Circle 环形进度条
### 使用指南
``` javascript
import { Circle } from 'vant';
Vue.use(Circle);
```
### 代码演示
#### 基础用法
通过 `rate` 指定目标进度,`v-model` 代表当前进度,`speed` 控制动画速度
```html
<van-circle
v-model="currentRate"
:rate="30"
:speed="100"
:text="text"
/>
```
``` javascript
export default {
data() {
return {
currentRate: 0
};
},
computed: {
text() {
return this.currentRate.toFixed(0) + '%'
}
}
};
```
#### 样式定制
```html
<van-circle
v-model="currentRate"
color="#13ce66"
fill="#fff"
size="120px"
layer-color="#eee"
:text="text"
:rate="rate"
:speed="100"
:clockwise="false"
:stroke-width="60"
/>
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| v-model | 当前进度 | `Number` | - |
| rate | 目标进度 | `Number` | `100` |
| size | 圆环直径 | `String` | `100px` |
| color | 进度条颜色 | `String` | `#38f` |
| layer-color | 轨道颜色 | `String` | `#fff` |
| fill | 填充颜色 | `String` | `none` |
| speed | 动画速度(单位为 rate/s| `Number` | - |
| text | 文字 | `String` | - |
| stroke-width | 进度条宽度 | `Number` | `40` |
| clockwise | 是否顺时针增加 | `Boolean` | `true` |
### Circle Slot
| 名称 | 说明 |
|-----------|-----------|
| - | 自定义文字内容 |
+65
View File
@@ -0,0 +1,65 @@
## Layout
Quickly and easily create layouts with `van-row` and `van-col`
### Install
``` javascript
import { Row, Col } from 'vant';
Vue.use(Row).use(Col);
```
### Usage
#### Basic Usage
Layout are based on 24-column. The attribute `span` in `Col` means the number of column the grid spans. Of course, You can use `offset` attribute to set number of spacing on the left side of the grid.
```html
<van-row>
<van-col span="8">span: 8</van-col>
<van-col span="8">span: 8</van-col>
<van-col span="8">span: 8</van-col>
</van-row>
<van-row>
<van-col span="4">span: 4</van-col>
<van-col span="10" offset="4">offset: 4, span: 10</van-col>
<van-col span="6">span: 6</van-col>
</van-row>
<van-row>
<van-col offset="12" span="12">offset: 12, span: 12</van-col>
</van-row>
```
#### Column Spacing
Set grid spacing using `gutter` attribute. The default value is 0
```html
<van-row gutter="20">
<van-col span="8">span: 8</van-col>
<van-col span="8">span: 8</van-col>
<van-col span="8">span: 8</van-col>
</van-row>
```
### API
#### Row
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| gutter | grid spacingpx | `String | Number` | - |
#### Column
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| span | number of column the grid spans | `String | Number` | - |
| offset | number of spacing on the left side of the grid | `String | Number` | - |
+61
View File
@@ -0,0 +1,61 @@
## Layout 布局
提供了`van-row``van-col`两个组件来进行行列布局
### 使用指南
``` javascript
import { Row, Col } from 'vant';
Vue.use(Row).use(Col);
```
### 代码演示
#### 基本用法
Layout 组件提供了`24列栅格`,通过在`Col`上添加`span`属性设置列所占的宽度百分比
此外,添加`offset`属性可以设置列的偏移宽度,计算方式与 span 相同
```html
<van-row>
<van-col span="8">span: 8</van-col>
<van-col span="8">span: 8</van-col>
<van-col span="8">span: 8</van-col>
</van-row>
<van-row>
<van-col span="4">span: 4</van-col>
<van-col span="10" offset="4">offset: 4, span: 10</van-col>
</van-row>
<van-row>
<van-col offset="12" span="12">offset: 12, span: 12</van-col>
</van-row>
```
#### 设置列元素间距
通过`gutter`属性可以设置列元素之间的间距,默认间距为 0
```html
<van-row gutter="20">
<van-col span="8">span: 8</van-col>
<van-col span="8">span: 8</van-col>
<van-col span="8">span: 8</van-col>
</van-row>
```
### API
#### Row
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| gutter | 列元素之间的间距(单位为px) | `String | Number` | - |
#### Column
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| span | 列元素宽度 | `String | Number` | - |
| offset | 列元素偏移距离 | `String | Number` | - |
+95
View File
@@ -0,0 +1,95 @@
## Collapse
### Install
``` javascript
import { Collapse, CollapseItem } from 'vant';
Vue.use(Collapse).use(CollapseItem);
```
### Usage
#### Basic Usage
Use `v-model` to control the name of active panels
```html
<van-collapse v-model="activeNames">
<van-collapse-item title="Title1" name="1">Content</van-collapse-item>
<van-collapse-item title="Title2" name="2">Content</van-collapse-item>
<van-collapse-item title="Title3" name="3">Content</van-collapse-item>
</van-collapse>
```
``` javascript
export default {
data() {
return {
activeNames: ['1']
};
}
};
```
#### Accordion
In accordion mode, only one panel can be expanded at the same time.
```html
<van-collapse v-model="activeName" accordion>
<van-collapse-item title="Title1" name="1">Content</van-collapse-item>
<van-collapse-item title="Title2" name="2">Content</van-collapse-item>
<van-collapse-item title="Title3" name="3">Content</van-collapse-item>
</van-collapse>
```
``` javascript
export default {
data() {
return {
activeName: '1'
};
}
};
```
#### Custom title
```html
<van-collapse v-model="activeNames">
<van-collapse-item name="1">
<div slot="title">Title1<van-icon name="question" /></div>
Content
</van-collapse-item>
<van-collapse-item title="Title2" name="2">
Content
</van-collapse-item>
</van-collapse>
```
### Collapse API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| v-model | names of current active panels | `Array | String | Number` | - |
| accordion | Whether to be accordion mode | `Boolean` | `false` |
### Collapse Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| change | Triggered when switch panel | activeNames: `string | array` |
### CollapseItem API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| name | Name | `String | Number` | `index` |
| title | Title | `String` | - |
### CollapseItem Slot
| name | Description |
|-----------|-----------|
| default | Content |
| title | Custom title |
+108
View File
@@ -0,0 +1,108 @@
## Collapse 折叠面板
### 使用指南
``` javascript
import { Collapse, CollapseItem } from 'vant';
Vue.use(Collapse).use(CollapseItem);
```
### 代码演示
#### 基础用法
通过`v-model`控制展开的面板列表,`activeNames`为数组格式
```html
<van-collapse v-model="activeNames">
<van-collapse-item title="有赞微商城" name="1">
提供多样店铺模板,快速搭建网上商城
</van-collapse-item>
<van-collapse-item title="有赞零售" name="2">
网店吸粉获客、会员分层营销、一机多种收款,告别经营低效和客户流失
</van-collapse-item>
<van-collapse-item title="有赞美业" name="3">
线上拓客,随时预约,贴心顺手的开单收银
</van-collapse-item>
</van-collapse>
```
``` javascript
export default {
data() {
return {
activeNames: ['1']
};
}
};
```
#### 手风琴
通过`accordion`可以设置为手风琴模式,最多展开一个面板,此时`activeName`为字符串格式
```html
<van-collapse v-model="activeName" accordion>
<van-collapse-item title="有赞微商城" name="1">
提供多样店铺模板,快速搭建网上商城
</van-collapse-item>
<van-collapse-item title="有赞零售" name="2">
网店吸粉获客、会员分层营销、一机多种收款,告别经营低效和客户流失
</van-collapse-item>
<van-collapse-item title="有赞美业" name="3">
线上拓客,随时预约,贴心顺手的开单收银
</van-collapse-item>
</van-collapse>
```
``` javascript
export default {
data() {
return {
activeName: '1'
};
}
};
```
#### 自定义标题内容
```html
<van-collapse v-model="activeNames">
<van-collapse-item name="1">
<div slot="title">有赞微商城<van-icon name="question" /></div>
提供多样店铺模板,快速搭建网上商城
</van-collapse-item>
<van-collapse-item title="有赞零售" name="2">
网店吸粉获客、会员分层营销、一机多种收款,告别经营低效和客户流失
</van-collapse-item>
</van-collapse>
```
### Collapse API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|-------------|
| v-model | 当前展开面板的 name | `Array | String | Number` | - |
| accordion | 是否开启手风琴模式 | `Boolean` | `false` |
### Collapse Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| change | 切换面板时触发 | activeNames: `string | array` |
### CollapseItem API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|-------------|
| name | 面板唯一标识符,默认为索引值 | `String | Number` | `index` |
| title | 标题 | `String` | - |
### CollapseItem Slot
| 名称 | 说明 |
|-----------|-----------|
| default | 面板内容 |
| title | 自定义标题内容 |
+181
View File
@@ -0,0 +1,181 @@
## Contact
### Install
``` javascript
import { ContactCard, ContactList, ContactEdit } from 'vant';
Vue
.use(ContactCard)
.use(ContactList)
.use(ContactEdit);
```
### Usage
#### Basic Usage
```html
<!-- Contact Card -->
<van-contact-card
:type="cardType"
:name="currentContact.name"
:tel="currentContact.tel"
@click="showList = true"
/>
<!-- Contact List -->
<van-popup v-model="showList" position="bottom">
<van-contact-list
v-model="chosenContactId"
:list="list"
@add="onAdd"
@edit="onEdit"
@select="onSelect"
/>
</van-popup>
<!-- Contact Edit -->
<van-popup v-model="showEdit" position="bottom">
<van-contact-edit
:contact-info="editingContact"
:is-edit="isEdit"
@save="onSave"
@delete="onDelete"
/>
</van-popup>
```
``` javascript
export default {
data() {
return {
chosenContactId: null,
editingContact: {},
showList: false,
showEdit: false,
isEdit: false,
list: [{
name: 'John Snow',
tel: '13000000000',
id: 0
}]
};
},
computed: {
cardType() {
return this.chosenContactId !== null ? 'edit' : 'add';
},
currentContact() {
const id = this.chosenContactId;
return id !== null ? this.list.filter(item => item.id === id)[0] : {};
}
},
methods: {
// add contact
onAdd() {
this.editingContact = { id: this.list.length };
this.isEdit = false;
this.showEdit = true;
},
// edit contact
onEdit(item) {
this.isEdit = true;
this.showEdit = true;
this.editingContact = item;
},
// select contact
onSelect() {
this.showList = false;
},
// save contact
onSave(info) {
this.showEdit = false;
this.showList = false;
if (this.isEdit) {
this.list = this.list.map(item => item.id === info.id ? info : item);
} else {
this.list.push(info);
}
this.chosenContactId = info.id;
},
// delete contact
onDelete(info) {
this.showEdit = false;
this.list = this.list.filter(item => item.id !== info.id);
if (this.chosenContactId === info.id) {
this.chosenContactId = null;
}
}
}
};
```
#### Uneditable
```html
<van-contact-card
type="edit"
name="John Snow"
tel="13000000000"
:editable="false"
/>
```
### ContactCard API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| type | Can be set to `add` `edit` | `String` | `add` |
| name | Name | `String` | - |
| tel | Phone | `String` | - |
| add-text | Add card text | `String` | `Add contact info` |
### ContactList API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|-------------|
| v-model | Id of chosen contact | `String | Number` | - |
| list | Contact list | `Array` | `[]` |
| add-text | Add button text | `String` | `Add new contact` |
### ContactList Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| add | Triggered when click add button | - |
| edit | Triggered when click edit button | item: contact objectindex |
| select | Triggered when select contact | item: contact object |
### ContactEdit API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|-------------|
| contact-info | Contact Info | `Object` | `[]` |
| is-edit | Whether is editing | `Boolean` | `false` |
| is-saving | Whether to show save button loading status | `Boolean` | `false` |
| is-deleting | Whether to show delete button loading status | `Boolean` | `false` |
| tel-validator | The method to validate tel | `(tel: string) => boolean` | - |
### ContactEdit Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| save | Triggered when click save button | contentcontact info |
| delete | Triggered when click delete button | contentcontact info |
### Contact Data Structure
| key | Description | Type |
|-----------|-----------|-----------|
| id | ID | `String | Number` |
| name | Name | `String` |
| tel | Phone | `String` |
+183
View File
@@ -0,0 +1,183 @@
## Contact 联系人
通过 Contact 组件可以实现联系人的展示、选择、编辑等功能。
### 使用指南
``` javascript
import { ContactCard, ContactList, ContactEdit } from 'vant';
Vue
.use(ContactCard)
.use(ContactList)
.use(ContactEdit);
```
### 代码演示
#### 基础用法
```html
<!-- 联系人卡片 -->
<van-contact-card
:type="cardType"
:name="currentContact.name"
:tel="currentContact.tel"
@click="showList = true"
/>
<!-- 联系人列表 -->
<van-popup v-model="showList" position="bottom">
<van-contact-list
v-model="chosenContactId"
:list="list"
@add="onAdd"
@edit="onEdit"
@select="onSelect"
/>
</van-popup>
<!-- 联系人编辑 -->
<van-popup v-model="showEdit" position="bottom">
<van-contact-edit
:contact-info="editingContact"
:is-edit="isEdit"
@save="onSave"
@delete="onDelete"
/>
</van-popup>
```
``` javascript
export default {
data() {
return {
chosenContactId: null,
editingContact: {},
showList: false,
showEdit: false,
isEdit: false,
list: [{
name: '张三',
tel: '13000000000',
id: 0
}]
};
},
computed: {
cardType() {
return this.chosenContactId !== null ? 'edit' : 'add';
},
currentContact() {
const id = this.chosenContactId;
return id !== null ? this.list.filter(item => item.id === id)[0] : {};
}
},
methods: {
// 添加联系人
onAdd() {
this.editingContact = { id: this.list.length };
this.isEdit = false;
this.showEdit = true;
},
// 编辑联系人
onEdit(item) {
this.isEdit = true;
this.showEdit = true;
this.editingContact = item;
},
// 选中联系人
onSelect() {
this.showList = false;
},
// 保存联系人
onSave(info) {
this.showEdit = false;
this.showList = false;
if (this.isEdit) {
this.list = this.list.map(item => item.id === info.id ? info : item);
} else {
this.list.push(info);
}
this.chosenContactId = info.id;
},
// 删除联系人
onDelete(info) {
this.showEdit = false;
this.list = this.list.filter(item => item.id !== info.id);
if (this.chosenContactId === info.id) {
this.chosenContactId = null;
}
}
}
};
```
#### 不可编辑
```html
<van-contact-card
type="edit"
name="张三"
tel="13000000000"
:editable="false"
/>
```
### ContactCard API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| type | 类型,可选值为 `add` `edit` | `String` | `add` |
| name | 联系人姓名 | `String` | - |
| tel | 联系人手机号 | `String` | - |
| add-text | 添加时的文案提示 | `String` | `添加订单联系人信息` |
### ContactList API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|-------------|
| v-model | 当前选中联系人的 id | `String | Number` | - |
| list | 联系人列表 | `Array` | `[]` |
| add-text | 新建按钮文案 | `String` | `新建联系人` |
### ContactList Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| add | 点击新增按钮时触发 | - |
| edit | 点击编辑按钮时触发 | item: 当前联系人对象,index: 索引 |
| select | 切换选中的联系人时触发 | item: 当前联系人对象,index: 索引 |
### ContactEdit API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|-------------|
| contact-info | 联系人信息 | `Object` | `[]` |
| is-edit | 是否为编辑联系人 | `Boolean` | `false` |
| is-saving | 是否显示保存按钮加载动画 | `Boolean` | `false` |
| is-deleting | 是否显示删除按钮加载动画 | `Boolean` | `false` |
| tel-validator | 手机号格式校验函数 | `(tel: string) => boolean` | - |
### ContactEdit Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| save | 点击保存按钮时触发 | content:表单内容 |
| delete | 点击删除按钮时触发 | content:表单内容 |
### 数据格式
#### 联系人数据格式
| key | 说明 | 类型 |
|-----------|-----------|-----------|
| id | 每位联系人的唯一标识 | `String | Number` |
| name | 联系人姓名 | `String` |
| tel | 联系人手机号 | `String` |
+114
View File
@@ -0,0 +1,114 @@
## Coupon
### Install
``` javascript
import { CouponCell, CouponList } from 'vant';
Vue.use(CouponCell).use(CouponList);
```
### Usage
#### Basic Usage
```html
<!-- Coupon Cell -->
<van-coupon-cell
:coupons="coupons"
:chosen-coupon="chosenCoupon"
@click="showList = true"
/>
<!-- Coupon List -->
<van-popup v-model="showList" position="bottom">
<van-coupon-list
:coupons="coupons"
:chosen-coupon="chosenCoupon"
:disabled-coupons="disabledCoupons"
@change="onChange"
@exchange="onExchange"
/>
</van-popup>
```
```javascript
const coupon = {
available: 1,
discount: 0,
denominations: 150,
origin_condition: 0,
reason: '',
value: 150,
name: 'Coupon name',
start_at: 1489104000,
end_at: 1514592000
};
export default {
data() {
return {
chosenCoupon: -1,
coupons: [coupon],
disabledCoupons: [coupon]
}
},
methods: {
onChange(index) {
this.showList = false;
this.chosenCoupon = index;
},
onExchange(code) {
this.coupons.push(coupon);
}
}
}
```
### CouponCell API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| title | Cell title | `String` | `Coupon` |
| chosen-coupon | Index of chosen coupon | `Number` | `-1` |
| coupons | Coupon list | `Array` | `[]` |
| editable | Cell editable | `Boolean` | `true` |
### CouponList API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| v-model | Current exchange code | `String` | - |
| chosen-coupon | Index of chosen coupon | `Number` | `-1` |
| coupons | Coupon list | `Array` | `[]` |
| disabled-coupons | Disabled voupon list | `Array` | `[]` |
| exchange-button-text | Exchange button text | `String` | `Exchange` |
| exchange-button-loading | Whether to show loading in exchange button | `Boolean` | `false` |
| exchange-button-disabled | Whether to disable exchange button | `Boolean` | `false` |
| exchange-min-length | Min length to enable exchange button | `Number` | `1` |
| displayed-coupon-index | Index of displayed coupon | `Number` | - |
| close-button-text | Close button text | `String` | `Close` |
| disabled-list-title | Disabled list title | `String` | `Unavailable` |
| input-placeholder | Input placeholder | `String` | `Coupon code` |
### CouponList Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| change | Triggered when change chosen coupon | index: index of chosen coupon |
| exchange | Triggered when exchange coupon | code: exchange code |
### Coupon Item Data Structure
| key | Description | Type |
|-----------|-----------|-----------|
| id | Id | `String` |
| name | Name | `String` |
| discount | Discount | `Number` |
| denominations | Denominations | `Number` |
| origin_condition | Condition | `Number` |
| start_at | Start time (Timestmap, unit second) | `Number` |
| end_at | End time (Timestmap, unit second) | `Number` |
| reason | Unavailable reason | `String` |
| value | Value | `Number` |
+116
View File
@@ -0,0 +1,116 @@
## Coupon 优惠券选择器
### 使用指南
``` javascript
import { CouponCell, CouponList } from 'vant';
Vue.use(CouponCell).use(CouponList);
```
### 代码演示
#### 基础用法
```html
<!-- 优惠券单元格 -->
<van-coupon-cell
:coupons="coupons"
:chosen-coupon="chosenCoupon"
@click="showList = true"
/>
<!-- 优惠券列表 -->
<van-popup v-model="showList" position="bottom">
<van-coupon-list
:coupons="coupons"
:chosen-coupon="chosenCoupon"
:disabled-coupons="disabledCoupons"
@change="onChange"
@exchange="onExchange"
/>
</van-popup>
```
```javascript
const coupon = {
available: 1,
discount: 0,
denominations: 150,
origin_condition: 0,
reason: '',
value: 150,
name: '优惠券名称',
start_at: 1489104000,
end_at: 1514592000
};
export default {
data() {
return {
chosenCoupon: -1,
coupons: [coupon],
disabledCoupons: [coupon]
}
},
methods: {
onChange(index) {
this.showList = false;
this.chosenCoupon = index;
},
onExchange(code) {
this.coupons.push(coupon);
}
}
}
```
### CouponCell API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| title | 单元格标题 | `String` | `优惠券码` |
| chosen-coupon | 当前选中优惠券的索引 | `Number` | `-1` |
| coupons | 可用优惠券列表 | `Array` | `[]` |
| editable | 能否切换优惠券 | `Boolean` | `true` |
### CouponList API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| v-model | 当前输入的兑换码 | `String` | - |
| chosen-coupon | 当前选中优惠券的索引 | `Number` | `-1` |
| coupons | 可用优惠券列表 | `Array` | `[]` |
| disabled-coupons | 不可用优惠券列表 | `Array` | `[]` |
| exchange-button-text | 兑换按钮文字 | `String` | `兑换` |
| exchange-button-loading | 是否在兑换按钮上显示加载动画 | `Boolean` | `false` |
| exchange-button-disabled | 是否禁用兑换按钮 | `Boolean` | `false` |
| exchange-min-length | 兑换码最小长度 | `Number` | `1` |
| displayed-coupon-index | 滚动至特定优惠券位置 | `Number` | - |
| show-close-button | 是否显示列表底部按钮 | `Boolean` | `true` |
| close-button-text | 列表底部按钮文字 | `String` | `不使用优惠` |
| disabled-list-title | 不可用券列表标题 | `String` | `不可用优惠` |
| input-placeholder | 输入框文字提示 | `String` | `请输入优惠码` |
| show-exchange-bar | 是否展示兑换栏 | `Boolean` | `true` |
### CouponList Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| change | 优惠券切换回调 | index, 选中优惠券的索引 |
| exchange | 兑换优惠券回调 | code, 兑换码 |
### 数据格式
#### 优惠券字段说明
| key | 说明 | 类型 |
|-----------|-----------|-----------|
| id | 优惠券 id | `String` |
| name | 优惠券名称 | `String` |
| discount | 折扣(0为满减券)88=>8.8折 | `Number` |
| denominations | 面值(0为折扣券)单位分 | `Number` |
| origin_condition | 满减条件(0为无门槛,满XX元可用)单位分 | `Number` |
| start_at | 卡有效开始时间 (时间戳, 单位秒) | `Number` |
| end_at | 卡失效日期 (时间戳, 单位秒) | `Number` |
| reason | 不可用原因 | `String` |
| value | 订单优惠金额,单位分 | `Number` |
+120
View File
@@ -0,0 +1,120 @@
## DatetimePicker
### Install
``` javascript
import { DatetimePicker } from 'vant';
Vue.use(DatetimePicker);
```
### Usage
#### Choose DateTime
```html
<van-datetime-picker
v-model="currentDate"
type="datetime"
:min-date="minDate"
:max-date="maxDate"
/>
```
```javascript
export default {
data() {
return {
minHour: 10,
maxHour: 20,
minDate: new Date(),
maxDate: new Date(2019, 10, 1),
currentDate: new Date()
};
}
};
```
#### Choose Date
```html
<van-datetime-picker
v-model="currentDate"
type="date"
:min-date="minDate"
/>
```
```js
export default {
data() {
return {
currentDate: new Date()
};
}
}
```
#### Choose Year-Month
```html
<van-datetime-picker
v-model="currentDate"
type="year-month"
:min-date="minDate"
/>
```
```js
export default {
data() {
return {
currentDate: new Date()
};
}
}
```
#### Choose Time
```html
<van-datetime-picker
v-model="currentDate"
type="time"
:min-hour="minHour"
:max-hour="maxHour"
/>
```
```js
export default {
data() {
return {
currentDate: '12:00'
};
}
}
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|-------------|
| type | Can be set to `date` `time` `year-month` | `String` | `datetime` |
| min-date | Min date | `Date` | Ten years ago on January 1 |
| max-date | Max date | `Date` | Ten years later on December 31 |
| min-hour | Min hour | `Number` | `0` |
| max-hour | Max hour | `Number` | `23` |
| title | Toolbar title | `String` | `''` |
| loading | Whether to show loading prompt | `Boolean` | `false` |
| item-height | Option height | `Number` | `44` |
| confirm-button-text | Text of confirm button | `String` | `Confirm` |
| cancel-button-text | Text of cancel button | `String` | `Cancel` |
| visible-item-count | Count of visible columns | `Number` | `5` |
### Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| change | Triggered when value changed | picker: picker instance |
| confirm | Triggered when click confirm button | value: current value |
| cancel | Triggered when click cancel button | - |
+133
View File
@@ -0,0 +1,133 @@
## DatetimePicker 时间选择
### 使用指南
``` javascript
import { DatetimePicker } from 'vant';
Vue.use(DatetimePicker);
```
### 代码演示
#### 选择完整时间
```html
<van-datetime-picker
v-model="currentDate"
type="datetime"
:min-date="minDate"
:max-date="maxDate"
/>
```
```javascript
export default {
data() {
return {
minHour: 10,
maxHour: 20,
minDate: new Date(),
maxDate: new Date(2019, 10, 1),
currentDate: new Date()
};
}
};
```
#### 选择日期(年月日)
```html
<van-datetime-picker
v-model="currentDate"
type="date"
:min-date="minDate"
/>
```
```js
export default {
data() {
return {
currentDate: new Date()
};
}
}
```
#### 选择日期(年月)
```html
<van-datetime-picker
v-model="currentDate"
type="year-month"
:min-date="minDate"
/>
```
```js
export default {
data() {
return {
currentDate: new Date()
};
}
}
```
#### 选择时间
```html
<van-datetime-picker
v-model="currentDate"
type="time"
:min-hour="minHour"
:max-hour="maxHour"
/>
```
```js
export default {
data() {
return {
currentDate: '12:00'
};
}
}
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|-------------|
| type | 类型,可选值为 `date` `time` `year-month` | `String` | `datetime` |
| min-date | 可选的最小日期 | `Date` | 十年前的 1 月 1 日 |
| max-date | 可选的最大日期 | `Date` | 十年后的 12 月 31 日 |
| min-hour | 可选的最小小时,针对 time 类型 | `Number` | `0` |
| max-hour | 可选的最大小时,针对 time 类型 | `Number` | `23` |
| title | 顶部栏标题 | `String` | `''` |
| loading | 是否显示加载状态 | `Boolean` | `false` |
| item-height | 选项高度 | `Number` | `44` |
| confirm-button-text | 确认按钮文字 | `String` | `确认` |
| cancel-button-text | 取消按钮文字 | `String` | `取消` |
| visible-item-count | 可见的选项个数 | `Number` | `5` |
### Event
| 事件名称 | 说明 | 回调参数 |
|-----------|-----------|-----------|
| change | 当值变化时触发的事件 | picker 实例 |
| confirm | 点击完成按钮时触发的事件 | 当前 value |
| cancel | 点击取消按钮时触发的事件 | - |
### change事件
在`change`事件中,可以获取到`picker`实例,对`picker`进行相应的更新等操作:
| 函数 | 说明 |
|-----------|-----------|
| getColumnValue(index) | 获取对应列中选中的值 |
| setColumnValue(index, value) | 设置对应列中选中的值 |
| getColumnValues(index) | 获取对应列中所有的备选值 |
| setColumnValues(index, values) | 设置对应列中所有的备选值 |
| getValues() | 获取所有列中被选中的值,返回一个数组 |
| setValues(values) | `values`为一个数组,设置所有列中被选中的值 |
+147
View File
@@ -0,0 +1,147 @@
## Dialog
### Install
```js
import { Dialog } from 'vant';
```
### Usage
#### Alert dialog
Used to prompt for some messages, only including one confirm button
```javascript
Dialog.alert({
title: 'Title',
message: 'Content'
}).then(() => {
// on close
});
Dialog.alert({
message: 'Content'
}).then(() => {
// on close
});
```
#### Confirm dialog
Used to confirm some messages, including a confirm button and a cancel button
```javascript
Dialog.confirm({
title: 'Title',
message: 'Content'
}).then(() => {
// on confirm
}).catch(() => {
// on cancel
});
```
#### $dialog Method
After import the Dialog component, the $dialog method is automatically mounted on Vue.prototype, making it easy to call within a vue component.
```js
export default {
mounted() {
this.$dialog.alert({
message: 'Content'
});
}
}
```
### Methods
| Name | Attribute | Return value | Description |
|-----------|-----------|-----------|-------------|
| Dialog | `options` | `Promise` | Show dialog |
| Dialog.alert | `options` | `Promise` | Show alert dialog |
| Dialog.confirm | `options` | `Promise` | Show confim dialog |
| Dialog.setDefaultOptions | `options` | `void` | Set default options of all dialogs |
| Dialog.resetDefaultOptions | - | `void` | Reset default options of all dialogs |
| Dialog.close | - | `void` | Close dialog |
### Options
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| title | Title | `String` | - |
| message | Message | `String` | - |
| showConfirmButton | Whether to show confirm button | `Boolean` | `true` |
| showCancelButton | Whether to show cancel button | `Boolean` | `false` |
| confirmButtonText | Confirm button text | `String` | `Confirm` |
| cancelButtonText | Cancel button test | `String` | `Cancel` |
| overlay | Whether to show overlay | `Boolean` | `true` |
| closeOnClickOverlay | Whether to close when click overlay | `Boolean` | `false` |
| lockScroll | Whether to lock body scroll | `Boolean` | `true` |
| beforeClose | Callback before closecall done to close dialog | (action: string, done: function) => void | - |
#### Advanced Usage
If you need to render vue components within a dialog, you can use dialog component.
```html
<van-dialog v-model="show" :asyncConfirm="onClickConfirmAsync">
<van-field
v-model="username"
label="Username"
placeholder="Username"
/>
<van-field
v-model="password"
type="password"
:label="Password"
:placeholder="Password"
/>
</van-dialog>
```
```js
Vue.use(Dialog);
export default {
data() {
return {
show: false,
username: '',
password: ''
};
},
methods: {
beforeClose(action, done) {
if (action === 'confirm') {
setTimeout(done, 1000);
} else {
done();
}
}
}
}
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| v-model | Whether to show dialog | `Boolean` | - |
| title | Title | `String` | - |
| message | Message | `String` | - |
| async-confirm | Whether to close asyncThe incoming function is triggered when you click confirm. | `Function` | - |
| show-confirm-button | Whether to show confirm button | `Boolean` | `true` |
| show-cancel-button | Whether to show cancel button | `Boolean` | `false` |
| confirm-button-text | Confirm button text | `String` | `Confirm` |
| cancel-button-text | Cancel button test | `String` | `Cancel` |
| overlay | Whether to show overlay | `Boolean` | `true` |
| close-on-click-overlay | Whether to close when click overlay | `Boolean` | `false` |
| lock-scroll | Whether to lock background scroll | `Boolean` | `true` |
| before-close | Callback before closecall done to close dialog | (action: string, done: function) => void | - |
### Event
| Event | Description | Parameters |
|-----------|-----------|-----------|
| confirm | Triggered when click confirm button | - |
| cancel | Triggered when click cancel button | - |
+152
View File
@@ -0,0 +1,152 @@
## Dialog 弹出框
Dialog 组件支持函数调用和组件调用两种形式
### 使用指南
```js
import { Dialog } from 'vant';
```
### 代码演示
#### 消息提示
用于提示一些消息,只包含一个确认按钮
```javascript
Dialog.alert({
title: '标题',
message: '弹窗内容'
}).then(() => {
// on close
});
Dialog.alert({
message: '弹窗内容'
}).then(() => {
// on close
});
```
#### 消息确认
用于确认消息,包含取消和确认按钮
```javascript
Dialog.confirm({
title: '标题',
message: '弹窗内容'
}).then(() => {
// on confirm
}).catch(() => {
// on cancel
});
```
#### 全局方法
引入 Dialog 组件后,会自动在 Vue 的 prototype 上挂载 $dialog 方法,在所有组件内部都可以直接调用此方法
```js
export default {
mounted() {
this.$dialog.alert({
message: '弹窗内容'
});
}
}
```
### 方法
| 方法名 | 参数 | 返回值 | 介绍 |
|-----------|-----------|-----------|-------------|
| Dialog | `options` | `Promise` | 展示弹窗 |
| Dialog.alert | `options` | `Promise` | 展示消息提示弹窗 |
| Dialog.confirm | `options` | `Promise` | 展示消息确认弹窗 |
| Dialog.setDefaultOptions | `options` | `void` | 修改默认配置,对所有 Dialog 生效 |
| Dialog.resetDefaultOptions | - | `void` | 重置默认配置,对所有 Dialog 生效 |
| Dialog.close | - | `void` | 关闭弹窗 |
### Options
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| title | 标题 | `String` | - |
| message | 内容 | `String` | - |
| showConfirmButton | 是否展示确认按钮 | `Boolean` | `true` |
| showCancelButton | 是否展示取消按钮 | `Boolean` | `false` |
| confirmButtonText | 确认按钮的文案 | `String` | `确认` |
| cancelButtonText | 取消按钮的文案 | `String` | `取消` |
| overlay | 是否展示蒙层 | `Boolean` | `true` |
| closeOnClickOverlay | 点击蒙层时是否关闭弹窗 | `Boolean` | `false` |
| lockScroll | 是否锁定背景滚动 | `Boolean` | `true` |
| beforeClose | 关闭前的回调函数,调用 done 后关闭弹窗 | (action: string, done: function) => void | - |
#### 高级用法
如果需要在弹窗内实现更复杂的交互,可以通过组件形式来调用 Dialog
```html
<van-dialog
v-model="show"
show-cancel-button
:before-close="beforeClose"
>
<van-field
v-model="username"
label="用户名"
placeholder="请输入用户名"
/>
<van-field
v-model="password"
type="password"
:label="密码"
:placeholder="请输入密码"
/>
</van-dialog>
```
```js
Vue.use(Dialog);
export default {
data() {
return {
show: false,
username: '',
password: ''
};
},
methods: {
beforeClose(action, done) {
if (action === 'confirm') {
setTimeout(done, 1000);
} else {
done();
}
}
}
}
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| v-model | 是否显示弹窗 | `Boolean` | - |
| title | 标题 | `String` | - |
| message | 内容 | `String` | - |
| show-confirm-button | 是否展示确认按钮 | `Boolean` | `true` |
| show-cancel-button | 是否展示取消按钮 | `Boolean` | `false` |
| confirm-button-text | 确认按钮的文案 | `String` | `确认` |
| cancel-button-text | 取消按钮的文案 | `String` | `取消` |
| overlay | 是否展示蒙层 | `Boolean` | `true` |
| close-on-click-overlay | 点击蒙层时是否关闭弹窗 | `Boolean` | `false` |
| lock-scroll | 是否锁定背景滚动 | `Boolean` | `true` |
| before-close | 关闭前的回调函数,调用 done 后关闭弹窗 | (action: string, done: function) => void | - |
### Event
| 事件 | 说明 | 回调参数 |
|-----------|-----------|-----------|
| confirm | 点击确认按钮时触发 | - |
| cancel | 点击取消按钮时触发 | - |
+138
View File
@@ -0,0 +1,138 @@
## Field
### Install
``` javascript
import { Field } from 'vant';
Vue.use(Field);
```
### Usage
#### Basic Usage
The value of filed is bound with v-model.
```html
<van-cell-group>
<van-field v-model="value" placeholder="Username" />
</van-cell-group>
```
#### Custom type
Use `type` prop to custom diffrent type fileds.
```html
<van-cell-group>
<van-field
v-model="username"
label="Username"
icon="clear"
placeholder="Username"
required
@click-icon="username = ''"
/>
<van-field
v-model="password"
type="password"
label="Password"
placeholder="Password"
required
/>
</van-cell-group>
```
#### Disabled
```html
<van-cell-group>
<van-field
value="Disabled"
label="Username"
disabled
/>
</van-cell-group>
```
#### Error info
Use `error` or `error-message` to show error info
```html
<van-cell-group>
<van-field
v-model="username"
label="Username"
placeholder="Username"
error
/>
<van-field
v-model="phone"
label="Phone"
placeholder="Phone"
error-message="Invalid phone"
/>
</van-cell-group>
```
#### Auto resize
Textarea Filed can be auto resize when has `autosize` prop
```html
<van-cell-group>
<van-field
v-model="message"
label="Message"
type="textarea"
placeholder="Message"
rows="1"
autosize
/>
</van-cell-group>
```
#### Insert button
Use button slot to insert button
```html
<van-cell-group>
<van-field
center
v-model="sms"
label="SMS"
placeholder="SMS"
icon="clear"
@click-icon="sms = ''"
>
<van-button slot="button" size="small" type="primary">Send SMS</van-button>
</van-field>
</van-cell-group>
```
### API
Filed support all native properties of input tagsuch as `maxlength`、`placeholder`、`readonly`、`autofocus`
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| value | Filed value | `String` | - |
| label | Filed label | `String` | - |
| type | Input type | `String` | `text` |
| disabled | Disable field | `Boolean` | `false` |
| error | Whether to show error info | `Boolean` | `false` |
| error-message | Error message | `String` | `''` |
| autosize | Textarea auto resizecan accpet an object, e.g. { maxHeight: 100, minHeight: 50 } | `Boolean | Object` | `false` |
| icon | Right side Icon name | `String` | - |
### Event
Filed support all native events of input tagsuch as `focus`、`blur`、`keypress`
| Event | Description | Parameters |
|-----------|-----------|-----------|
| click-icon | Triggered when click the icon of filed | - |
### Slot
| name | Description |
|-----------|-----------|
| label | Custom label |
| icon | Custom icon |
| button | Insert button |
+140
View File
@@ -0,0 +1,140 @@
## Field 输入框
`input``textarea`的输入框。
### 使用指南
``` javascript
import { Field } from 'vant';
Vue.use(Field);
```
### 代码演示
#### 基础用法
通过 v-model 绑定输入框的值
```html
<van-cell-group>
<van-field v-model="value" placeholder="请输入用户名" />
</van-cell-group>
```
#### 自定义类型
根据`type`属性定义不同类型的输入框
```html
<van-cell-group>
<van-field
v-model="username"
label="用户名"
icon="clear"
placeholder="请输入用户名"
required
@click-icon="username = ''"
/>
<van-field
v-model="password"
type="password"
label="密码"
placeholder="请输入密码"
required
/>
</van-cell-group>
```
#### 禁用输入框
```html
<van-cell-group>
<van-field
value="输入框已禁用"
label="用户名"
disabled
/>
</van-cell-group>
```
#### 错误提示
通过`error`或者`error-message`属性增加对应的错误提示
```html
<van-cell-group>
<van-field
v-model="username"
label="用户名"
placeholder="请输入用户名"
error
/>
<van-field
v-model="phone"
label="手机号"
placeholder="请输入手机号"
error-message="手机号格式错误"
/>
</van-cell-group>
```
#### 高度自适应
对于 textarea,可以通过`autosize`属性设置高度自适应
```html
<van-cell-group>
<van-field
v-model="message"
label="留言"
type="textarea"
placeholder="请输入留言"
rows="1"
autosize
/>
</van-cell-group>
```
#### 插入按钮
通过 button slot 可以在输入框尾部插入按钮
```html
<van-cell-group>
<van-field
center
v-model="sms"
label="短信验证码"
placeholder="请输入短信验证码"
icon="clear"
@click-icon="sms = ''"
>
<van-button slot="button" size="small" type="primary">发送验证码</van-button>
</van-field>
</van-cell-group>
```
### API
Filed 默认支持 Input 标签所有的原生属性,比如 `maxlength`、`placeholder`、`readonly`、`autofocus` 等
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|-------------|
| label | 标签 | `String` | - |
| value | 当前输入的值 | `String` | - |
| type | 可设置为任意原生类型, 如 `number` `tel` `textarea` | `String` | `text` |
| disabled | 是否禁用输入框 | `Boolean` | `false` |
| error | 是否将输入内容标红 | `Boolean` | `false` |
| error-message | 底部错误提示文案 | `String` | `''` |
| autosize | 自适应内容高度,只对 textarea 有效,可传入对象,如 { maxHeight: 100, minHeight: 50 },单位为 px | `Boolean | Object` | `false` |
| icon | 输入框尾部图标 (可选值见 Icon 组件) | `String` | - |
### Event
Filed 默认支持 Input 标签所有的原生事件,如 `focus`、`blur`、`keypress` 等
| 事件 | 说明 | 回调参数 |
|-----------|-----------|-----------|
| click-icon | 点击尾部图标时触发 | - |
### Slot
| 名称 | 说明 |
|-----------|-----------|
| label | 自定义输入框标签 |
| icon | 自定义输入框尾部图标 |
| button | 自定义输入框尾部按钮 |
+78
View File
@@ -0,0 +1,78 @@
## GoodsAction
### Install
``` javascript
import {
GoodsAction,
GoodsActionBigBtn,
GoodsActionMiniBtn
} from 'vant';
Vue
.use(GoodsAction)
.use(GoodsActionBigBtn)
.use(GoodsActionMiniBtn);
```
### Usage
#### Basic Usage
```html
<van-goods-action>
<van-goods-action-mini-btn icon="chat" text="Icon1" @click="onClickMiniBtn" />
<van-goods-action-mini-btn icon="cart" text="Icon2" @click="onClickMiniBtn" />
<van-goods-action-big-btn text="Button1" @click="onClickBigBtn" />
<van-goods-action-big-btn text="Button2" @click="onClickBigBtn" primary />
</van-goods-action>
```
```javascript
export default {
methods: {
onClickMiniBtn() {
Toast('Click Icon');
},
onClickBigBtn() {
Toast('Click Button');
}
}
}
```
#### Icon info
Use `info` prop to show messages in upper right corner of icon
```html
<van-goods-action>
<van-goods-action-mini-btn icon="chat" text="Icon1" />
<van-goods-action-mini-btn icon="cart" text="Icon2" info="5" />
<van-goods-action-mini-btn icon="shop" text="Icon3" />
<van-goods-action-big-btn text="Button1" />
<van-goods-action-big-btn text="Button2" primary />
</van-goods-action>
```
### API
#### GoodsActionMiniBtn
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| text | Button text | `String` | - |
| icon | Icon | `String` | - |
| icon-class | Icon class name | `String` | `''` |
| info | Info message | `String | Number` | - |
| url | Link | `String` | - |
| to | Target route of the link, same as to of `vue-router` | `String | Object` | - |
| replace | If true, the navigation will not leave a history record | `String` | `false` |
#### GoodsActionBigBtn
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| text | Button text | `String` | - |
| primary | Is primary button (red color) | `Boolean` | `false` |
| url | Link | `String` | - |
| to | Target route of the link, same as to of `vue-router` | `String | Object` | - |
| replace | If true, the navigation will not leave a history record | `String` | `false` |
+78
View File
@@ -0,0 +1,78 @@
## GoodsAction 商品页行动点
### 使用指南
``` javascript
import {
GoodsAction,
GoodsActionBigBtn,
GoodsActionMiniBtn
} from 'vant';
Vue
.use(GoodsAction)
.use(GoodsActionBigBtn)
.use(GoodsActionMiniBtn);
```
### 代码演示
#### 基础用法
```html
<van-goods-action>
<van-goods-action-mini-btn icon="chat" text="客服" @click="onClickMiniBtn" />
<van-goods-action-mini-btn icon="cart" text="购物车" @click="onClickMiniBtn" />
<van-goods-action-big-btn text="加入购物车" @click="onClickBigBtn" />
<van-goods-action-big-btn text="立即购买" @click="onClickBigBtn" primary />
</van-goods-action>
```
```javascript
export default {
methods: {
onClickMiniBtn() {
Toast('点击图标');
},
onClickBigBtn() {
Toast('点击按钮');
}
}
}
```
#### 图标提示
通过`info`属性在图标右上角增加相应的提示
```html
<van-goods-action>
<van-goods-action-mini-btn icon="chat" text="客服" />
<van-goods-action-mini-btn icon="cart" text="购物车" info="5" />
<van-goods-action-mini-btn icon="shop" text="店铺" />
<van-goods-action-big-btn text="加入购物车" />
<van-goods-action-big-btn text="立即购买" primary />
</van-goods-action>
```
### API
#### GoodsActionMiniBtn
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| text | 按钮文字 | `String` | - |
| icon | 图标 | `String` | - |
| icon-class | 图标额外类名 | `String` | `''` |
| info | 图标右上角提示信息 | `String | Number` | - |
| url | 跳转链接 | `String` | - |
| to | 路由跳转对象,同 `vue-router` 的 to | `String | Object` | - |
| replace | 跳转时是否替换当前 history | `String` | `false` |
#### GoodsActionBigBtn
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| text | 按钮文字 | `String` | - |
| primary | 是否主行动按钮,主行动按钮默认为红色 | `Boolean` | `false` |
| url | 跳转链接 | `String` | - |
| to | 路由跳转对象,同 `vue-router` 的 to | `String | Object` | - |
| replace | 跳转时是否替换当前 history | `String` | `false` |
+60
View File
@@ -0,0 +1,60 @@
## Icon
### Install
``` javascript
import { Icon } from 'vant';
Vue.use(Icon);
```
### Usage
#### Basic Usage
View all usable icons on the right.
```html
<van-icon name="success" />
```
#### Use local font file
Icon uses font file in `yzcdn.cn` by defaultif you want to use the local font fileplease import the following css file.
```js
import 'vant/lib/vant-css/icon-local.css';
```
#### Add custom iconfont
```css
@font-face {
font-family: 'custom-iconfont';
src: url('./iconfont.ttf') format('truetype');
}
.van-icon {
font-family: 'vant-icon', 'custom-iconfont' !important;
}
.van-icon-extra:before {
content: '\e626';
}
```
```html
<van-icon name="extra" />
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| name | Icon name | `String` | `''` |
| info | Info message | `String | Number` | `''` |
| color | Icon color | `String` | `''` | - |
### Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| click | Triggered when click icon | - |
+61
View File
@@ -0,0 +1,61 @@
## Icon 图标
### 使用指南
``` javascript
import { Icon } from 'vant';
Vue.use(Icon);
```
### 代码演示
#### 基础用法
设置`name`属性为对应的图标名称即可,所有可用的图标名称见右侧列表
```html
<van-icon name="success" />
```
#### 使用本地字体文件
Icon 组件默认引用 `yzcdn.cn` 域名下的字体文件,如果想要使用本地字体文件,请引入下面的 css 文件
```js
import 'vant/lib/vant-css/icon-local.css';
```
#### 自定义图标
如果需要在现有 Icon 的基础上使用更多图标,可以引入你需要的 iconfont 对应的 ttf 文件和样式,之后就可以在 Icon 组件中直接使用
```css
@font-face {
font-family: 'custom-iconfont';
src: url('./iconfont.ttf') format('truetype');
}
.van-icon {
font-family: 'vant-icon', 'custom-iconfont' !important;
}
.van-icon-extra:before {
content: '\e626';
}
```
```html
<van-icon name="extra" />
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| name | 图标名称 | `String` | `''` |
| info | 图标右上角文字提示 | `String | Number` | `''` |
| color | 图标颜色 | `String` | `''` | - |
### Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| click | 点击图标时触发 | - |
+45
View File
@@ -0,0 +1,45 @@
## ImagePreview
### Install
```js
import { ImagePreview } from 'vant';
```
### Usage
#### Basic Usage
```javascript
ImagePreview([
'https://img.yzcdn.cn/1.jpg',
'https://img.yzcdn.cn/2.jpg'
]);
```
#### Custom Start Position
```javascript
ImagePreview([
'https://img.yzcdn.cn/1.jpg',
'https://img.yzcdn.cn/2.jpg'
], 1);
```
#### Close Manually
```javascript
const instance = ImagePreview([
'https://img.yzcdn.cn/1.jpg',
'https://img.yzcdn.cn/2.jpg'
]);
setTimeout(() => {
instance.close();
}, 1000);
```
### Arguments
| Attribute | Description | Type |
|-----------|-----------|-----------|
| imageUrls | Image URL list | `Array` |
+49
View File
@@ -0,0 +1,49 @@
## ImagePreview 图片预览
### 使用指南
`ImagePreview`和其他组件不同,不是通过HTML结构的方式来使用,而是通过函数调用的方式。使用前需要先引入它。
```js
import { ImagePreview } from 'vant';
```
### 代码演示
#### 基础用法
```javascript
ImagePreview([
'https://img.yzcdn.cn/1.jpg',
'https://img.yzcdn.cn/2.jpg'
]);
```
#### 指定初始位置
```javascript
ImagePreview([
'https://img.yzcdn.cn/1.jpg',
'https://img.yzcdn.cn/2.jpg'
], 1);
```
#### 手动关闭
```javascript
const instance = ImagePreview([
'https://img.yzcdn.cn/1.jpg',
'https://img.yzcdn.cn/2.jpg'
]);
setTimeout(() => {
instance.close();
}, 1000);
```
### 方法参数
| 参数名 | 说明 | 类型 |
|-----------|-----------|-----------|
| imageUrls | 需要预览的图片 | `Array` |
| startPosition | 图片预览起始位置索引 | `Number` |
+61
View File
@@ -0,0 +1,61 @@
## Lazyload
### Install
```js
import Vue from 'vue';
import { Lazyload } from 'vant';
Vue.use(Lazyload, options);
```
### Usage
#### Basic Usage
```html
<img v-for="img in imageList" v-lazy="img" >
```
```javascript
export default {
data() {
return {
imageList: [
'https://img.yzcdn.cn/1.jpg',
'https://img.yzcdn.cn/2.jpg'
]
};
}
}
```
#### Lazyload Background Image
Use `v-lazy:background-image` to set background url, and declare the height of the container.
```html
<div v-for="img in imageList" v-lazy:background-image="img" />
```
#### Lazyload Component
```html
<lazy-component>
<img v-for="img in imageList" v-lazy="img" >
</lazy-component>
```
### Options
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| loading | Src of the image while loading | `String` | - |
| error | Src of the image upon load fail | `String` | - |
| preload | Proportion of pre-loading height | `String` | - |
| attempt | Attempts count | `Number` | `3` |
| listenEvents | Events that you want vue listen for | `Array` | `scroll`... |
| adapter | Dynamically modify the attribute of element | `Object` | - |
| filter | The image's listener filter | `Object` | - |
| lazyComponent | Lazyload component | `Boolean` | `false` |
See more[ vue-lazyload ](https://github.com/hilongjw/vue-lazyload)
+67
View File
@@ -0,0 +1,67 @@
## Lazyload 图片懒加载
### 使用指南
`Lazyload``Vue`指令,所以需要使用它必须将它注册到`Vue`的指令中。
```js
import Vue from 'vue';
import { Lazyload } from 'vant';
Vue.use(Lazyload, options);
```
### 代码演示
#### 基础用法
`v-lazy`指令的值设置为你需要懒加载的图片
```html
<img v-for="img in imageList" v-lazy="img" >
```
```javascript
export default {
data() {
return {
imageList: [
'https://img.yzcdn.cn/1.jpg',
'https://img.yzcdn.cn/2.jpg'
]
};
}
}
```
#### 背景图懒加载
和图片懒加载不同,背景图懒加载需要使用`v-lazy:background-image`,值设置为背景图片的地址,需要注意的是必须声明容器高度。
```html
<div v-for="img in imageList" v-lazy:background-image="img" />
```
#### 懒加载模块
懒加载模块需要使用到`lazy-component`,将需要懒加载的内容放在`lazy-component`中即可。
```html
<lazy-component>
<img v-for="img in imageList" v-lazy="img" >
</lazy-component>
```
### Options
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| loading | 加载时的图片 | `String` | - |
| error | 错误时的图片 | `String` | - |
| preload | 预加载高度的比例 | `String` | - |
| attempt | 尝试次数 | `Number` | `3` |
| listenEvents | 监听的事件 | `Array` | `scroll`等 |
| adapter | 适配器 | `Object` | - |
| filter | 图片url过滤 | `Object` | - |
| lazyComponent | 是否能懒加载模块 | `Boolean` | `false` |
更多内容请参照:[vue-lazyload 官方文档](https://github.com/hilongjw/vue-lazyload)
+66
View File
@@ -0,0 +1,66 @@
## List
A list component to show items and control loading status.
### Install
``` javascript
import { List } from 'vant';
Vue.use(List);
```
### Usage
#### Basic Usage
```html
<van-list
v-model="loading"
:finished="finished"
@load="onLoad"
>
<van-cell v-for="item in list" :key="item" :title="item + ''" />
</van-list>
```
```js
export default {
data() {
return {
list: [],
loading: false,
finished: false
};
},
methods: {
onLoad() {
setTimeout(() => {
for (let i = 0; i < 10; i++) {
this.list.push(this.list.length + 1);
}
this.loading = false;
if (this.list.length >= 40) {
this.finished = true;
}
}, 500);
}
}
}
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| loading | Whether to show loading infothe `load` event will not be triggered when loading | `Boolean` | `false` |
| finished | Whether loading is finishedthe `load` event will not be triggered when finished | `Boolean` | `false` |
| offset | The load event will be triggered when the distance between the scrollbar and the bottom is less than offset | `Number` | `300` |
| loading-text | Loading text | `String` | `Loading...` |
| immediate-check | Whether to check loading position immediately after mounted | `Boolean` | `true` |
### Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| load | Triggered when the distance between the scrollbar and the bottom is less than offset | - |
+66
View File
@@ -0,0 +1,66 @@
## List 列表
瀑布流滚动加载,用于控制长列表的展示
### 使用指南
``` javascript
import { List } from 'vant';
Vue.use(List);
```
### 代码演示
#### 基础用法
```html
<van-list
v-model="loading"
:finished="finished"
@load="onLoad"
>
<van-cell v-for="item in list" :key="item" :title="item + ''" />
</van-list>
```
```js
export default {
data() {
return {
list: [],
loading: false,
finished: false
};
},
methods: {
onLoad() {
setTimeout(() => {
for (let i = 0; i < 10; i++) {
this.list.push(this.list.length + 1);
}
this.loading = false;
if (this.list.length >= 40) {
this.finished = true;
}
}, 500);
}
}
}
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| loading | 是否显示加载中提示,加载过程中不触发`load`事件 | `Boolean` | `false` |
| finished | 是否已加载完成,加载完成后不再触发`load`事件 | `Boolean` | `false` |
| offset | 滚动条与底部距离小于 offset 时触发`load`事件 | `Number` | `300` |
| loading-text | 加载中提示文案 | `String` | `加载中...` |
| immediate-check | 是否在初始化时立即执行滚动位置检查 | `Boolean` | `true` |
### Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| load | 滚动条与底部距离小于 offset 时触发 | - |
+32
View File
@@ -0,0 +1,32 @@
## Loading
### Install
``` javascript
import { Loading } from 'vant';
Vue.use(Loading);
```
### Usage
#### Circular
```html
<van-loading color="black" />
<van-loading color="white" />
```
#### Spinner
```html
<van-loading type="spinner" color="black" />
<van-loading type="spinner" color="white" />
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| color | Can be set to `black` `white` | `String` | `black` | |
| type | Can be set to `circular` `spinner` | `String` | `circular` |
| size | Size | `String` | `30px` |
+32
View File
@@ -0,0 +1,32 @@
## Loading 加载
### 使用指南
``` javascript
import { Loading } from 'vant';
Vue.use(Loading);
```
### 代码演示
#### Circular
```html
<van-loading color="black" />
<van-loading color="white" />
```
#### Spinner
```html
<van-loading type="spinner" color="black" />
<van-loading type="spinner" color="white" />
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| color | 颜色,可选值为 `block` `white` | `String` | `black` |
| type | 类型,可选值为 `circular` `spinner` | `String` | `circular` |
| size | 大小 | `String` | `30px` |
+40
View File
@@ -0,0 +1,40 @@
## Internationalization
The default language of Vant is Chinese. If you want to use other languages, you can follow the instructions below.
### Switch languages
Vant supports multiple languages with the Locale component, and the `Locale.use` method allows you to switch to diffrent languages.
```js
import { Locale } from 'vant';
import enUS from 'vant/lib/locale/lang/en-US';
Locale.use('en-US', enUS);
```
### Modify default configs
Use `Locale.add` method to modify the default configs.
```js
import { Locale } from 'vant';
const messages = {
'en-US': {
vanPicker: {
confirm: 'Close'
}
}
};
Locale.add(messages);
```
### Config files
Current supported languages:
| Language | Filename |
|-----------|-----------|
| Chinese | zh-CN |
| English | en-US |
| Traditional Chinese | zh-HK |
View all language configs [Here](https://github.com/youzan/vant/tree/dev/packages/locale/lang).
+41
View File
@@ -0,0 +1,41 @@
## 国际化
Vant 默认采用中文作为语言,如果需要使用其他语言,可以参考下面的方案
### 多语言切换
Vant 通过 Locale 组件实现多语言支持,使用 `Locale.use` 方法可以切换当前使用的语言。
```js
import { Locale } from 'vant';
import enUS from 'vant/lib/locale/lang/en-US';
Locale.use('en-US', enUS);
```
### 修改默认文案
通过 `Locale.add` 方法可以实现文案的修改和扩展,示例如下:
```js
import { Locale } from 'vant';
const messages = {
'zh-CN': {
vanPicker: {
confirm: '关闭' // 将'确认'修改为'关闭'
}
}
};
Locale.add(messages);
```
### 配置文件
目前支持的语言:
| 语言 | 文件名 |
|-----------|-----------|
| 简体中文 | zh-CN |
| 英语 | en-US |
| 繁體中文 | zh-HK |
在 [这里](https://github.com/youzan/vant/tree/dev/packages/locale/lang) 查看所有的 i18n 配置文件。
+71
View File
@@ -0,0 +1,71 @@
## NavBar
### Install
``` javascript
import { NavBar } from 'vant';
Vue.use(NavBar);
```
### Usage
#### Basic Usage
```html
<van-nav-bar
title="Title"
left-text="Back"
right-text="Button"
left-arrow
@click-left="onClickLeft"
@click-right="onClickRight"
/>
```
```js
export default {
methods: {
onClickLeft() {
Toast('Back');
},
onClickRight() {
Toast('Button');
}
}
}
```
#### Advanced Usage
```html
<van-nav-bar title="Title" left-text="Back" left-arrow>
<van-icon name="search" slot="right" />
</van-nav-bar>
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| title | Title | `String` | `''` |
| left-text | Left Text | `String` | `''` |
| right-text | Right Text | `String` | `''` |
| left-arrow | Whether to show left arrow | `Boolean` | `false` |
| fixed | Whether to fixed top | `Boolean` | `false` |
| z-index | Z-index | `Number` | `1` |
### Slot
| name | Description |
|-----------|-----------|
| title | Custom title |
| left | Custom left side content |
| right | Custom right side content |
### Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| click-left | Triggered when click left button | - |
| click-right | Triggered when click right button | - |
+72
View File
@@ -0,0 +1,72 @@
## NavBar 导航栏
### 使用指南
``` javascript
import { NavBar } from 'vant';
Vue.use(NavBar);
```
### 代码演示
#### 基础用法
```html
<van-nav-bar
title="标题"
left-text="返回"
right-text="按钮"
left-arrow
@click-left="onClickLeft"
@click-right="onClickRight"
/>
```
```js
export default {
methods: {
onClickLeft() {
Toast('返回');
},
onClickRight() {
Toast('按钮');
}
}
}
```
#### 高级用法
通过 slot 定制内容
```html
<van-nav-bar title="标题" left-text="返回" left-arrow>
<van-icon name="search" slot="right" />
</van-nav-bar>
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| title | 标题 | `String` | `''` |
| left-text | 左侧文案 | `String` | `''` |
| right-text | 右侧文案 | `String` | `''` |
| left-arrow | 是否显示左侧箭头 | `Boolean` | `false` |
| fixed | 是否固定在顶部 | `Boolean` | `false` |
| z-index | 元素 z-index | `Number` | `1` |
### Slot
| 名称 | 说明 |
|-----------|-----------|
| title | 自定义标题 |
| left | 自定义左侧区域内容 |
| right | 自定义右侧区域内容 |
### Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| click-left | 点击左侧按钮时触发 | - |
| click-right | 点击右侧按钮时触发 | - |
+58
View File
@@ -0,0 +1,58 @@
## NoticeBar
### Install
``` javascript
import { NoticeBar } from 'vant';
Vue.use(NoticeBar);
```
### Usage
#### Basic Usage
```html
<van-notice-bar
text="Only those who have the patience to do simple things perfectly ever acquire the skill to do difficult things easily."
left-icon="https://img.yzcdn.cn/1.png"
/>
```
#### Disable scroll
```html
<van-notice-bar :scrollable="false">
Only those who have the patience to do simple things perfectly ever acquire the skill to do difficult things easily.
</van-notice-bar>
```
#### Mode
```html
<van-notice-bar mode="closeable">
Only those who have the patience to do simple things perfectly ever acquire the skill to do difficult things easily.
</van-notice-bar>
<van-notice-bar mode="link">
Only those who have the patience to do simple things perfectly ever acquire the skill to do difficult things easily.
</van-notice-bar>
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| mode | Mode, can be set to `closeable` `link` | `String` | `''` |
| delay | Animation delay (s) | `Number` | `1` |
| speed | Scroll speed (px/s) | `Number` | `50` |
| scrollable | Whether to scroll content | `Boolean` | `true` |
| left-icon | Image url of left icon | `String` | - |
| color | Text color | `String` | `#f60` |
| background | Background color | `String` | `#fff7cc` |
### Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| click | Triggered when click notice bar | - |
+61
View File
@@ -0,0 +1,61 @@
## NoticeBar 通告栏
### 使用指南
``` javascript
import { NoticeBar } from 'vant';
Vue.use(NoticeBar);
```
### 代码演示
#### 基础用法
```html
<van-notice-bar
text="足协杯战线连续第2年上演广州德比战,上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。"
left-icon="https://img.yzcdn.cn/1.png"
/>
```
#### 禁用滚动
文字内容多于一行时,可通过`scrollable`参数控制是否开启滚动
```html
<van-notice-bar :scrollable="false">
足协杯战线连续第2年上演广州德比战,上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。
</van-notice-bar>
```
#### 通告栏模式
默认模式为空,支持`closeable`和`link`。
```html
<!-- closeable 模式,在右侧显示关闭按钮 -->
<van-notice-bar mode="closeable">
足协杯战线连续第2年上演广州德比战,上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。
</van-notice-bar>
<!-- link 模式,在右侧显示链接箭头 -->
<van-notice-bar mode="link">
足协杯战线连续第2年上演广州德比战,上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。
</van-notice-bar>
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| mode | 通告栏模式,可选值为 `closeable` `link` | `String` | `''` |
| delay | 动画延迟时间 (s) | `Number` | `1` |
| speed | 滚动速率 (px/s) | `Number` | `50` |
| scrollable | 是否在长度溢出时滚动播放 | `Boolean` | `true` |
| left-icon | 左侧图标图片 URL | `String` | - |
| color | 文本颜色 | `String` | `#f60` |
| background | 滚动条背景 | `String` | `#fff7cc` |
### Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| click | 点击事件回调 | - |
+84
View File
@@ -0,0 +1,84 @@
## NumberKeyboard
### Install
``` javascript
import { NumberKeyboard } from 'vant';
Vue.use(NumberKeyboard);
```
### Usage
#### Default Style
```html
<van-button @touchstart.native.stop="show = true">
Show Keyboard
</van-button>
<van-number-keyboard
:show="show"
extra-key="."
close-button-text="Close"
@blur="show = false"
@input="onInput"
@delete="onDelete"
/>
```
```javascript
export default {
data() {
return {
show: true
}
},
methods: {
onInput(value) {
Toast(value);
},
onDelete() {
Toast('delete');
}
}
}
```
#### Custom Style
```html
<van-number-keyboard
:show="show"
theme="custom"
extra-key="."
close-button-text="Close"
@blur="show = false"
@input="onInput"
@delete="onDelete"
/>
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| show | Whether to show keyboard | `Boolean` | - |
| theme | Keyboard themecan be set to `default` `custom` | `String` | `default` |
| title | Keyboard title | `String` | - |
| transition | Whether to show transition animation | `Boolean` | `true` |
| z-index | Keyboard z-index | `Number` | `100` |
| extra-key | Content of bottom left key | `String` | `''` |
| close-button-text | Close button text | `String` | `-` |
| show-delete-key | Whether to show delete button | `Boolean` | `true` |
| hide-on-click-outside | Whether to hide keyboard when click outside | `Boolean` | `true` |
### Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| input | Triggered when keydown | key: Content of the key |
| delete | Triggered when press delete key | - |
| blur | Triggered when blur keyboard | - |
| show | Triggered when keyboard is fully displayed. | - |
| hide | Triggered when keyboard is fully hidden. | - |
+84
View File
@@ -0,0 +1,84 @@
## NumberKeyboard 数字键盘
### 使用指南
``` javascript
import { NumberKeyboard } from 'vant';
Vue.use(NumberKeyboard);
```
### 代码演示
#### 默认样式
```html
<van-button @touchstart.native.stop="show = true">
弹出默认键盘
</van-button>
<van-number-keyboard
:show="show"
extra-key="."
close-button-text="完成"
@blur="show = false"
@input="onInput"
@delete="onDelete"
/>
```
```javascript
export default {
data() {
return {
show: true
}
},
methods: {
onInput(value) {
Toast(value);
},
onDelete() {
Toast('delete');
}
}
}
```
#### 自定义样式
```html
<van-number-keyboard
:show="show"
theme="custom"
extra-key="."
close-button-text="完成"
@blur="show = false"
@input="onInput"
@delete="onDelete"
/>
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| show | 是否显示键盘 | `Boolean` | - |
| theme | 样式风格,可选值为 `default` `custom` | `String` | `default` |
| title | 键盘标题 | `String` | - |
| transition | 是否开启过场动画 | `Boolean` | `true` |
| z-index | 键盘 z-index | `Number` | `100` |
| extra-key | 左下角按键内容 | `String` | `''` |
| close-button-text | 关闭按钮文字,空则不展示 | `String` | `-` |
| show-delete-key | 是否展示删除按钮 | `Boolean` | `true` |
| hide-on-click-outside | 点击外部时是否收起键盘 | `Boolean` | `true` |
### Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| input | 点击按键时触发 | key: 按键内容 |
| delete | 点击删除键时触发 | - |
| blur | 点击非键盘区域时触发 | - |
| show | 键盘完全弹出时触发 | - |
| hide | 键盘完全收起时触发 | - |
+69
View File
@@ -0,0 +1,69 @@
## Pagination
### Install
``` javascript
import { Pagination } from 'vant';
Vue.use(Pagination);
```
### Usage
#### Basic Usage
```html
<van-pagination
v-model="currentPage"
:total-items="24"
:items-per-page="5"
/>
```
```javascript
export default {
data() {
return {
currentPage: 1
}
}
}
```
#### Simple mode
```html
<van-pagination
v-model="currentPage"
:page-count="12"
mode="simple"
/>
```
#### Show ellipses
```html
<van-pagination
v-model="currentPage"
:total-items="125"
:show-page-size="3"
force-ellipses
/>
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| v-model | Current page number | `Number` | - |
| mode | Mode, can be set to `simple` `multi` | `String` | `multi` |
| items-per-page | Item number per page | `Number` | `10` |
| prev-text | Previous text | `String` | `Previous` |
| next-text | Next text | `String` | `Next` |
| show-page-size | Count of page size to show | `Number` | `5` |
| force-ellipses | Whether to show ellipses | `Boolean` | `false` |
### Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| change | Triggered on page change | - |
+71
View File
@@ -0,0 +1,71 @@
## Pagination 分页
### 使用指南
``` javascript
import { Pagination } from 'vant';
Vue.use(Pagination);
```
### 代码演示
#### 基础用法
```html
<van-pagination
v-model="currentPage"
:total-items="24"
:items-per-page="5"
/>
```
```javascript
export default {
data() {
return {
currentPage: 1
}
}
}
```
#### 简单模式
```html
<van-pagination
v-model="currentPage"
:page-count="12"
mode="simple"
/>
```
#### 显示省略号
```html
<van-pagination
v-model="currentPage"
:total-items="125"
:show-page-size="3"
force-ellipses
/>
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| v-model | 当前页码 | `Number` | - |
| mode | 显示模式,可选值为 `simple` `multi` | `String` | `multi` |
| items-per-page | 每页记录数 | `Number` | `10` |
| previous-text | 上一页 | `String` | `上一页` |
| next-text | 下一页 | `String` | `下一页` |
| show-page-size | 显示的页码个数 | `Number` | `5` |
| force-ellipses | 显示省略号 | `Boolean` | `false` |
### Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| change | 页码改变时触发 | - |
+47
View File
@@ -0,0 +1,47 @@
## Panel
### Install
``` javascript
import { Panel } from 'vant';
Vue.use(Panel);
```
### Usage
#### Basic Usage
```html
<van-panel title="Title" desc="Description" status="Status">
<div>Content</div>
</van-panel>
```
#### Advanced Usage
```html
<van-panel title="Title" desc="Description" status="Status">
<div>Content</div>
<div slot="footer">
<van-button size="small">Button</van-button>
<van-button size="small" type="danger">Button</van-button>
</div>
</van-panel>
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| title | Title | `String` | - |
| desc | Description | `String` | - |
| status | Status | `String` | - |
### Slot
| name | Description |
|-----------|-----------|
| - | Default slot |
| header | Custom header |
| footer | Custom footer |
+48
View File
@@ -0,0 +1,48 @@
## Panel 面板
### 使用指南
``` javascript
import { Panel } from 'vant';
Vue.use(Panel);
```
### 代码演示
#### 基础用法
面板只是一个容器,里面可以放入自定义的内容
```html
<van-panel title="标题" desc="描述信息" status="状态">
<div>内容</div>
</van-panel>
```
#### 高级用法
使用`slot`自定义内容
```html
<van-panel title="标题" desc="描述信息" status="状态">
<div>内容</div>
<div slot="footer">
<van-button size="small">按钮</van-button>
<van-button size="small" type="danger">按钮</van-button>
</div>
</van-panel>
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| title | 标题 | `String` | - |
| desc | 描述 | `String` | - |
| status | 状态 | `String` | - |
### Slot
| 名称 | 说明 |
|-----------|-----------|
| - | 自定义内容 |
| header | 自定义 header |
| footer | 自定义 footer |
+65
View File
@@ -0,0 +1,65 @@
## PasswordInput
The PasswordInput component is usually used with [NumberKeyboard](#/en-US/number-keyboard) Component.
### Install
``` javascript
import { PasswordInput, NumberKeyboard } from 'vant';
Vue.use(PasswordInput).use(NumberKeyboard);
```
### Usage
#### Basic Usage
```html
<!-- PasswordInput -->
<van-password-input
:value="value"
info="Some tips"
@focus="showKeyboard = true"
/>
<!-- NumberKeyboard -->
<van-number-keyboard
:show="showKeyboard"
@input="onInput"
@delete="onDelete"
@blur="showKeyboard = false"
/>
```
```javascript
export default {
data() {
return {
value: '123',
showKeyboard: true
};
},
methods: {
onInput(key) {
this.value = (this.value + key).slice(0, 6);
},
onDelete() {
this.value = this.value.slice(0, this.value.length - 1);
}
}
}
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| value | Password value | `String` | `''` |
| length | Maxlength of password | `Number` | `6` |
| info | Bottom info | `String` | - |
| error-info | Bottom error info | `String` | - |
### Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| focus | Triggered when input get focused | - |
+65
View File
@@ -0,0 +1,65 @@
## PasswordInput 密码输入框
密码输入框组件通常与 [数字键盘](#/zh-CN/number-keyboard) 组件配合使用
### 使用指南
``` javascript
import { PasswordInput, NumberKeyboard } from 'vant';
Vue.use(PasswordInput).use(NumberKeyboard);
```
### 代码演示
#### 基础用法
```html
<!-- 密码输入框 -->
<van-password-input
:value="value"
info="密码为 6 位数字"
@focus="showKeyboard = true"
/>
<!-- 数字键盘 -->
<van-number-keyboard
:show="showKeyboard"
@input="onInput"
@delete="onDelete"
@blur="showKeyboard = false"
/>
```
```javascript
export default {
data() {
return {
value: '123',
showKeyboard: true
};
},
methods: {
onInput(key) {
this.value = (this.value + key).slice(0, 6);
},
onDelete() {
this.value = this.value.slice(0, this.value.length - 1);
}
}
}
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| value | 密码值 | `String` | `''` |
| length | 密码最大长度 | `Number` | `6` |
| info | 输入框下方提示 | `String` | - |
| error-info | 输入框下方错误提示 | `String` | - |
### Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| focus | 输入框聚焦时触发 | - |
+173
View File
@@ -0,0 +1,173 @@
## Picker
The Picker component is usually used with [Popup](#/en-US/popup) Component.
### Install
``` javascript
import { Picker } from 'vant';
Vue.use(Picker);
```
### Usage
#### Basic Usage
```html
<van-picker :columns="columns" @change="onChange" />
```
```javascript
export default {
data() {
return {
columns: ['Delaware', 'Florida', 'Georqia', 'Indiana', 'Maine']
};
},
methods: {
onChange(picker, value, index) {
Toast(`Value: ${value}, Index: ${index}`);
}
}
};
```
#### Disable option
```html
<van-picker :columns="columns" />
```
```javascript
export default {
data() {
return {
columns: [
{ text: 'Delaware', disabled: true },
{ text: 'Florida' },
{ text: 'Georqia' }
]
};
}
};
```
#### Show Toolbar
```html
<van-picker
show-toolbar
title="Title"
:columns="columns"
@cancel="onCancel"
@confirm="onConfirm"
/>
```
```javascript
export default {
data() {
return {
columns: ['Delaware', 'Florida', 'Georqia', 'Indiana', 'Maine']
}
},
methods: {
onConfirm(value, index) {
Toast(`Value: ${value}, Index: ${index}`);
},
onCancel() {
Toast('Cancel');
}
}
};
```
#### Multi columns
```html
<van-picker :columns="columns" @change="onChange" />
```
```javascript
const states = {
'Group1': ['Delaware', 'Florida', 'Georqia', 'Indiana', 'Maine'],
'Group2': ['Alabama', 'Kansas', 'Louisiana', 'Texas']
};
export default {
data() {
return {
columns: [
{
values: Object.keys(states),
className: 'column1'
},
{
values: states.Group1,
className: 'column2',
defaultIndex: 2
}
]
};
},
methods: {
onChange(picker, values) {
picker.setColumnValues(1, states[values[0]]);
}
}
};
```
#### Loading
When Picker columns data is acquired asynchronously, use `loading` prop to show loading prompt
```html
<van-picker :columns="columns" loading />
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| columns | Columns data | `Array` | `[]` |
| show-toolbar | Whether to show toolbar | `Boolean` | `false` |
| title | Toolbar title | `String` | `''` |
| loading | Whether to show loading prompt | `Boolean` | `false` |
| value-key | Key of option text | `String` | `text` |
| item-height | Option height | `Number` | `44` |
| confirm-button-text | Text of confirm button | `String` | `Confirm` |
| cancel-button-text | Text of cancel button | `String` | `Cancel` |
| visible-item-count | Count of visible columns | `Number` | `5` |
### Event
Picker events will pass different parameters according to the columns are single or multiple
| Event | Description | Arguments |
|-----------|-----------|-----------|
| confirm | Triggered when click confirm button | Single columncurrent valuecurrent index<br>Multiple columnscurrent valuescurrent indexes |
| cancel | Triggered when click cancel button | Single columncurrent valuecurrent index<br>Multiple columnscurrent valuescurrent indexes |
| change | Triggered when current option changed | Single columnPicker instance, current valuecurrent index<br>Multiple columnsPicker instance, current valuescolumn index |
### Data struct of columns
| key | Description |
|-----------|-----------|
| values | Value of column |
| defaultIndex | Default value index |
| className | ClassName for this column |
### Picker instance
You can get the picker instance in 'change' event, and
| Method | Description |
|-----------|-----------|
| getValues() | Get current values of all columns |
| setValues(values) | Set current values of all columns |
| getIndexes() | Get current indexes of all columns |
| setIndexes(indexes) | Set current indexes of all columns |
| getColumnValue(columnIndex) | Get current value of the column |
| setColumnValue(columnIndex, value) | Set current value of the column |
| getColumnIndex(columnIndex) | Get current index of the column |
| setColumnIndex(columnIndex, optionIndex) | Set current index of the column |
| getColumnValues(columnIndex) | Get columns data of the column |
| setColumnValues(columnIndex, values) | Set columns data of the column |
+176
View File
@@ -0,0 +1,176 @@
## Picker 选择器
选择器组件通常与 [弹出层](#/zh-CN/popup) 组件配合使用
### 使用指南
``` javascript
import { Picker } from 'vant';
Vue.use(Picker);
```
### 代码演示
#### 基础用法
```html
<van-picker :columns="columns" @change="onChange" />
```
```javascript
export default {
data() {
return {
columns: ['杭州', '宁波', '温州', '嘉兴', '湖州']
};
},
methods: {
onChange(picker, value, index) {
Toast(`当前值:${value}, 当前索引:${index}`);
}
}
};
```
#### 禁用选项
选项可以为对象结构,通过设置 disabled 来禁用该选项
```html
<van-picker :columns="columns" />
```
```javascript
export default {
data() {
return {
columns: [
{ text: '杭州', disabled: true },
{ text: '宁波' },
{ text: '温州' }
]
};
}
};
```
#### 展示顶部栏
```html
<van-picker
show-toolbar
title="标题"
:columns="columns"
@cancel="onCancel"
@confirm="onConfirm"
/>
```
```javascript
export default {
data() {
return {
columns: ['杭州', '宁波', '温州', '嘉兴', '湖州']
}
},
methods: {
onConfirm(value, index) {
Toast(`当前值:${value}, 当前索引:${index}`);
},
onCancel() {
Toast('取消');
}
}
};
```
#### 多列联动
```html
<van-picker :columns="columns" @change="onChange" />
```
```javascript
const citys = {
'浙江': ['杭州', '宁波', '温州', '嘉兴', '湖州'],
'福建': ['福州', '厦门', '莆田', '三明', '泉州']
};
export default {
data() {
return {
columns: [
{
values: Object.keys(citys),
className: 'column1'
},
{
values: citys['浙江'],
className: 'column2',
defaultIndex: 2
}
]
};
},
methods: {
onChange(picker, values) {
picker.setColumnValues(1, citys[values[0]]);
}
}
};
```
#### 加载状态
当 Picker 数据是通过异步获取时,可以通过 `loading` 属性显示加载提示
```html
<van-picker :columns="columns" loading />
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| columns | 对象数组,配置每一列显示的数据 | `Array` | `[]` |
| show-toolbar | 是否显示顶部栏 | `Boolean` | `false` |
| title | 顶部栏标题 | `String` | `''` |
| loading | 是否显示加载状态 | `Boolean` | `false` |
| value-key | 选项对象中,文字对应的 key | `String` | `text` |
| item-height | 选项高度 | `Number` | `44` |
| confirm-button-text | 确认按钮文字 | `String` | `确认` |
| cancel-button-text | 取消按钮文字 | `String` | `取消` |
| visible-item-count | 可见的选项个数 | `Number` | `5` |
### Event
Picker 组件的事件会根据 columns 是单列或多列返回不同的参数
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| confirm | 点击完成按钮时触发 | 单列:选中值,选中值对应的索引<br>多列:所有列选中值,所有列选中值对应的索引 |
| cancel | 点击取消按钮时触发 | 单列:选中值,选中值对应的索引<br>多列:所有列选中值,所有列选中值对应的索引 |
| change | 选项改变时触发 | 单列:Picker 实例,选中值,选中值对应的索引<br>多列:Picker 实例,所有列选中值,当前列对应的索引 |
### Columns 数据结构
当传入多列数据时,`columns`为一个对象数组,数组中的每一个对象配置每一列,每一列有以下`key`
| key | 说明 |
|-----------|-----------|
| values | 列中对应的备选值 |
| defaultIndex | 初始选中项的索引,默认为 0 |
| className | 为对应列添加额外的`class` |
### Picker 实例
在`change`事件中,可以获取到`picker`实例,通过实例方法可以灵活控制 Picker 内容
| 函数 | 说明 |
|-----------|-----------|
| getValues() | 获取所有列选中的值,返回一个数组 |
| setValues(values) | 设置所有列选中的值 |
| getIndexes() | 获取所有列选中值对应的索引,返回一个数组 |
| setIndexes(indexes) | 设置所有列选中值对应的索引 |
| getColumnValue(columnIndex) | 获取对应列选中的值 |
| setColumnValue(columnIndex, value) | 设置对应列选中的值 |
| getColumnIndex(columnIndex) | 获取对应列选中项的索引 |
| setColumnIndex(columnIndex, optionIndex) | 设置对应列选中项的索引 |
| getColumnValues(columnIndex) | 获取对应列中所有选项 |
| setColumnValues(columnIndex, values) | 设置对应列中所有选项 |
+56
View File
@@ -0,0 +1,56 @@
## Popup
### Install
``` javascript
import { Popup } from 'vant';
Vue.use(Popup);
```
### Usage
#### Basic Usage
Popup is located in the middle of the screen by default
```html
<van-popup v-model="show">Content</van-popup>
```
```javascript
export default {
data() {
return {
show: false
}
}
};
```
#### Position
Use `position` prop to set popup display position
```html
<van-popup v-model="show" position="top" :overlay="false">
Content
</van-popup>
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| v-model | Whether to show popup | `Boolean` | `false` |
| overlay | Whether to show overlay | `Boolean` | `true` |
| position | Can be set to `top` `bottom` `right` `left` | `String` | - |
| overlay-class | Custom overlay class | `String` | `` |
| overlay-style | Custom overlay style | `Object` | - |
| close-on-click-overlay | Close popup when click overlay | `Boolean` | `true` |
| transition | Transition | `String` | `popup-slide` |
| lock-scroll | Whether to lock background scroll | `Boolean` | `true` |
| get-container | Return the mount node for Popup | `() => HTMLElement` | - |
### Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| click-overlay | Triggered when click overlay | - |
+56
View File
@@ -0,0 +1,56 @@
## Popup 弹出层
### 使用指南
``` javascript
import { Popup } from 'vant';
Vue.use(Popup);
```
### 代码演示
#### 基础用法
`popup`默认从中间弹出
```html
<van-popup v-model="show">内容</van-popup>
```
```javascript
export default {
data() {
return {
show: false
}
}
};
```
#### 弹出位置
通过`position`属性设置 Popup 弹出位置
```html
<van-popup v-model="show" position="top" :overlay="false">
内容
</van-popup>
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| v-model | 当前组件是否显示 | `Boolean` | `false` |
| overlay | 是否显示背景蒙层 | `Boolean` | `true` |
| lock-scroll | 是否锁定背景滚动 | `Boolean` | `true` |
| position | 可选值为 `top` `bottom` `right` `left` | `String` | - |
| overlay-class | 自定义蒙层 class | `String` | `` |
| overlay-style | 自定义蒙层样式 | `Object` | `` |
| close-on-click-overlay | 点击蒙层是否关闭 Popup | `Boolean` | `true` |
| transition | transition 名称 | `String` | `popup-slide` |
| get-container | 指定弹出层挂载的 HTML 节点 | `() => HTMLElement` | - |
### Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| click-overlay | 点击蒙层时触发 | - |
+49
View File
@@ -0,0 +1,49 @@
## Progress
### Install
``` javascript
import { Progress } from 'vant';
Vue.use(Progress);
```
### Usage
#### Basic Usage
Use 'percentage' prop to set current progress
```html
<van-progress :percentage="0" />
<van-progress :percentage="46" />
<van-progress :percentage="100" />
```
#### Inactive
```html
<van-progress inactive :percentage="0" />
<van-progress inactive :percentage="46" />
<van-progress inactive :percentage="100" />
```
#### Custom Style
Use `pivot-text` to custom textuse `color` to custom bar color
```html
<van-progress pivot-text="Red" color="#ed5050" :percentage="26" />
<van-progress pivot-text="Orange" color="#f60" :percentage="46" />
<van-progress pivot-text="Yellow" color="#f09000" :percentage="66" />
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| inactive | Whether to be gray | `Boolean` | `false` |
| percentage | Percentage | `Number` | `false` |
| show-pivot | Whether to show text | `Boolean` | `true` |
| pivot-text | Text | `String` | percentage |
| color | Color | `String` | `#38f` |
| text-color | Text color | `String` | `#fff` |
+51
View File
@@ -0,0 +1,51 @@
## Progress 进度条
### 使用指南
``` javascript
import { Progress } from 'vant';
Vue.use(Progress);
```
### 代码演示
#### 基础用法
进度条默认为蓝色,使用`percentage`属性来设置当前进度
```html
<van-progress :percentage="0" />
<van-progress :percentage="46" />
<van-progress :percentage="100" />
```
#### 进度条置灰
```html
<van-progress inactive :percentage="0" />
<van-progress inactive :percentage="46" />
<van-progress inactive :percentage="100" />
```
#### 样式定制
可以使用`pivot-text`属性自定义文字,`color`属性自定义进度条颜色
```html
<van-progress pivot-text="红色" color="#ed5050" :percentage="26" />
<van-progress pivot-text="橙色" color="#f60" :percentage="46" />
<van-progress pivot-text="黄色" color="#f09000" :percentage="66" />
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| inactive | 是否置灰 | `Boolean` | `false` |
| percentage | 进度百分比 | `Number` | `false` |
| show-pivot | 是否显示进度文字 | `Boolean` | `true` |
| pivot-text | 文字显示 | `String` | 百分比文字 |
| color | 进度条颜色 | `String` | `#38f` |
| text-color | 进度条文字颜色 | `String` | `#fff` |
+68
View File
@@ -0,0 +1,68 @@
## PullRefresh
### Install
``` javascript
import { PullRefresh } from 'vant';
Vue.use(PullRefresh);
```
### Usage
#### Basic Usage
The `refresh` event will be triggered when pull refresh, you should set `v-model` to `false` to reset loading status after process refresh event.
```html
<van-pull-refresh v-model="isLoading" @refresh="onRefresh">
<p>Refresh Count: {{ count }}</p>
</van-pull-refresh>
```
```javascript
export default {
data() {
return {
count: 0,
isLoading: false
}
},
methods: {
onRefresh() {
setTimeout(() => {
this.$toast('Refresh Success');
this.isLoading = false;
this.count++;
}, 500);
}
}
}
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| v-model | Loading status | `Boolean` | - |
| pulling-text | Text to show when pulling | `String` | `Pull to refresh...` |
| loosing-text | Text to show when loosing | `String` | `Loose to refresh...` |
| loading-text | Text to show when loading | `String` | `Loading...` |
| animation-duration | Animation duration | `Number` | `300` |
| head-height | Height of head | `Number` | `50` |
### Event
| Event | Description | Parameters |
|-----------|-----------|-----------|
| refresh | Triggered when pull refresh | - |
### Slot
| name | Description |
|-----------|-----------|
| - | Default slot |
| normal | Content of head when at normal status |
| pulling | Content of head when at pulling |
| loosing | Content of head when at loosing |
| loading | Content of head when at loading |
+67
View File
@@ -0,0 +1,67 @@
## PullRefresh 下拉刷新
### 使用指南
``` javascript
import { PullRefresh } from 'vant';
Vue.use(PullRefresh);
```
### 代码演示
#### 基础用法
下拉刷新时会触发 `refresh` 事件,在事件的回调函数中可以进行同步或异步操作,操作完成后将 `v-model` 设置为 `false`,表示加载完成。
```html
<van-pull-refresh v-model="isLoading" @refresh="onRefresh">
<p>刷新次数: {{ count }}</p>
</van-pull-refresh>
```
```javascript
export default {
data() {
return {
count: 0,
isLoading: false
}
},
methods: {
onRefresh() {
setTimeout(() => {
this.$toast('刷新成功');
this.isLoading = false;
this.count++;
}, 500);
}
}
}
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| v-model | 是否在加载中 | `Boolean` | - |
| pulling-text | 下拉过程中顶部文案 | `String` | `下拉即可刷新...` |
| loosing-text | 释放过程中顶部文案 | `String` | `释放即可刷新...` |
| loading-text | 加载过程中顶部文案 | `String` | `加载中...` |
| animation-duration | 动画时长 | `Number` | `300` |
| head-height | 顶部内容高度 | `Number` | `50` |
### Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| refresh | 下拉刷新时触发 | - |
### Slot
| 名称 | 说明 |
|-----------|-----------|
| - | 自定义内容 |
| normal | 非下拉状态时顶部内容 |
| pulling | 下拉过程中顶部内容 |
| loosing | 释放过程中顶部内容 |
| loading | 加载过程中顶部内容 |
+75
View File
@@ -0,0 +1,75 @@
## Radio
### Install
``` javascript
import { RadioGroup, Radio } from 'vant';
Vue.use(RadioGroup);
Vue.use(Radio);
```
### Usage
#### Basic Usage
Use `v-model` to bind the name of checked radio
```html
<van-radio-group v-model="radio">
<van-radio name="1">Radio 1</van-radio>
<van-radio name="2">Radio 2</van-radio>
</van-radio-group>
```
```javascript
export default {
data() {
return {
radio: '1'
}
}
};
```
#### Disabled
```html
<van-radio-group v-model="radio" disabled>
<van-radio name="1">Radio 1</van-radio>
<van-radio name="2">Radio 2</van-radio>
</van-radio-group>
```
#### Inside a Cell
```html
<van-radio-group v-model="radio">
<van-cell-group>
<van-cell :title="Radio 1" clickable @click="radio = '1'">
<van-radio name="1" />
</van-cell>
<van-cell :title="Radio 2" clickable @click="radio = '2'">
<van-radio name="2" />
</van-cell>
</van-cell-group>
</van-radio-group>
```
### Radio API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| name | Radio name | `any` | - |
| disabled | Whether to disable radio | `Boolean` | `false` |
### RadioGroup API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| v-model | Name of checked radio | `any` | - |
| disabled | Diable all radios | `Boolean` | `false` |
### RadioGroup Event
| Event | Description | Parameters |
|-----------|-----------|-----------|
| change | Triggered when value changed | current value |
+77
View File
@@ -0,0 +1,77 @@
## Radio 单选框
### 使用指南
``` javascript
import { RadioGroup, Radio } from 'vant';
Vue.use(RadioGroup);
Vue.use(Radio);
```
### 代码演示
#### 基础用法
通过`v-model`绑定值当前选中项的 name
```html
<van-radio-group v-model="radio">
<van-radio name="1">单选框 1</van-radio>
<van-radio name="2">单选框 2</van-radio>
</van-radio-group>
```
```javascript
export default {
data() {
return {
radio: '1'
}
}
};
```
#### 禁用状态
通过`disabled`属性禁止选项切换,在`van-radio`上设置`diabled`可以禁用单个选项
```html
<van-radio-group v-model="radio" disabled>
<van-radio name="1">单选框 1</van-radio>
<van-radio name="2">单选框 2</van-radio>
</van-radio-group>
```
#### 与 Cell 组件一起使用
此时你需要再引入`Cell`和`CellGroup`组件。
```html
<van-radio-group v-model="radio">
<van-cell-group>
<van-cell :title="单选框 1" clickable @click="radio = '1'">
<van-radio name="1" />
</van-cell>
<van-cell :title="单选框 2" clickable @click="radio = '2'">
<van-radio name="2" />
</van-cell>
</van-cell-group>
</van-radio-group>
```
### Radio API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| name | 唯一标识符 | 任意类型 | - |
| disabled | 是否为禁用状态 | `Boolean` | `false` |
### RadioGroup API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| v-model | 当前选中项的 name | 任意类型 | - |
| disabled | 是否禁用所有单选框 | `Boolean` | `false` |
### RadioGroup Event
| 事件名称 | 说明 | 回调参数 |
|-----------|-----------|-----------|
| change | 当绑定值变化时触发的事件 | 当前选中项的 name |
+56
View File
@@ -0,0 +1,56 @@
## Rate
### Install
``` javascript
import { Rate } from 'vant';
Vue.use(Rate);
```
### Usage
#### Basic Usage
```html
<van-rate v-model="value" />
```
```javascript
export default {
data() {
return {
value: 3
};
}
}
```
#### Custom Color
```html
<van-rate
v-model="value"
:size="25"
:count="6"
color="#2ba"
void-color="#ceefe8"
/>
```
#### Disabled
```html
<van-rate v-model="value" disabled />
```
### Rate API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| v-model | Current rate | `Number` | - |
| count | Count | `Number` | `5` |
| size | Icon size (px) | `Number` | `20` |
| color | Selected color | `String` | `#ffd21e` |
| void-color | Void color | `String` | `#c7c7c7` |
| disabled-color | Disabled color | `String` | `#bdbdbd` |
| disabled | Whether to disable rate | `Boolean` | `false` |
+56
View File
@@ -0,0 +1,56 @@
## Rate 评分
### 使用指南
``` javascript
import { Rate } from 'vant';
Vue.use(Rate);
```
### 代码演示
#### 基础用法
```html
<van-rate v-model="value" />
```
```javascript
export default {
data() {
return {
value: 3
};
}
}
```
#### 自定义颜色
```html
<van-rate
v-model="value"
:size="25"
:count="6"
color="#2ba"
void-color="#ceefe8"
/>
```
#### 禁用状态
```html
<van-rate v-model="value" disabled />
```
### Rate API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| v-model | 当前分值 | `Number` | - |
| count | 图标总数 | `Number` | `5` |
| size | 图标大小 (px) | `Number` | `20` |
| color | 选中时的颜色 | `String` | `#ffd21e` |
| void-color | 未选中时的颜色 | `String` | `#c7c7c7` |
| disabled-color | 不可选时的颜色 | `String` | `#bdbdbd` |
| disabled | 是否禁用评分 | `Boolean` | `false` |
+79
View File
@@ -0,0 +1,79 @@
## Search
### Install
``` javascript
import { Search } from 'vant';
Vue.use(Search);
```
### Usage
#### Basic Usage
```html
<van-search placeholder="Placeholder" v-model="value" />
```
```javascript
export default {
data() {
value: ''
}
}
```
#### Listen to Events
`search` event will be triggered when click the search button on the keyboard.
`cancel` event will be triggered when click the cancel button.
Tips: There will be a search button on the keyboard when Search is inside a form in iOS.
```html
<form action="/">
<van-search
v-model="value"
placeholder="Placeholder"
show-action
@search="onSearch"
@cancel="onCancel"
/>
</form>
```
#### Custom Button
Use `action` slot to custom right button, `cancel` event will no longer be triggered when use this slot
```html
<van-search
v-model="value"
show-action
@search="onSearch"
>
<div slot="action" @click="onSearch">Search</div>
</van-search>
```
### API
Search support all native properties of input tagsuch as `maxlength`、`placeholder`、`readonly`、`autofocus`
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| placeholder | Input placeholder | `String` | - |
| background | Background color | `String` | `#f2f2f2` |
| show-action | Whether to show right button | `Boolean` | `false` |
### Event
Search support all native events of input tagsuch as `focus`、`blur`、`keypress`
| Event | Description | Arguments |
|-----------|-----------|-----------|
| cancel | Triggered when click cancel button | - |
| search | Triggered when confirm search | - |
### Slot
| name | Description |
|-----------|-----------|
| action | Custom right button, displayed when `showAction` is true |
+69
View File
@@ -0,0 +1,69 @@
## Search 搜索
### 使用指南
``` javascript
import { Search } from 'vant';
Vue.use(Search);
```
### 代码演示
#### 基础用法
`van-search` 中,v-model 用于控制搜索框中的文字。background 可以自定义搜索框外部背景色。
```html
<van-search placeholder="请输入商品名称" v-model="value" />
```
#### 监听对应事件
`van-search` 提供了 search 和 cancel 事件。search 事件在用户点击键盘上的 搜索/回车 按钮触发。cancel 事件在用户点击搜索框右侧取消按钮时触发
Tips: 在 `van-search` 外层增加 form 标签,并且 action 不为空,即可在 IOS 弹出的输入法中显示搜索按钮
```html
<form action="/">
<van-search
v-model="value"
placeholder="请输入商品名称"
show-action
@search="onSearch"
@cancel="onCancel"
/>
</form>
```
#### 自定义行动按钮
`van-search` 支持自定义右侧取消按钮,使用名字为 action 的 slot 即可。使用此 slot 以后,原有的 cancel 事件不再生效。
```html
<van-search
v-model="value"
show-action
@search="onSearch"
>
<div slot="action" @click="onSearch">搜索</div>
</van-search>
```
### API
Search 默认支持 Input 标签所有的原生属性,比如 `maxlength`、`placeholder`、`readony`、`autofocus` 等
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| background | 搜索框背景色 | `String` | `#f2f2f2` |
| show-action | 是否在搜索框右侧显示取消按钮 | `Boolean` | `false` |
### Event
Search 默认支持 Input 标签所有的原生事件,如 `focus`、`blur`、`keypress` 等
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| cancel | 取消搜索 | - |
| search | 确定搜索 | - |
### Slot
| 名称 | 说明 |
|-----------|-----------|
| action | 自定义搜索框右侧按钮,需要在`showAction`为 true 时才会显示 |
+257
View File
@@ -0,0 +1,257 @@
## Sku
### Install
```javascript
import { Sku } from 'vant';
Vue.use(Sku);
```
### Usage
#### Basic Usage
```html
<van-sku
v-model="showBase"
:sku="sku"
:goods="goods"
:goods-id="goodsId"
:hide-stock="sku.hide_stock"
:quota="quota"
:quota-used="quotaUsed"
:reset-stepper-on-hide="resetStepperOnHide"
:reset-selected-sku-on-hide="resetSelectedSkuOnHide"
:close-on-click-overlay="closeOnClickOverlay"
:disable-stepper-input="disableStepperInput"
:message-config="messageConfig"
@buy-clicked="onBuyClicked"
@add-cart="onAddCartClicked"
/>
```
#### Custom Stepper Config
```html
<van-sku
v-model="showBase"
:sku="sku"
:goods="goods"
:goods-id="goodsId"
:hide-stock="sku.hide_stock"
:quota="quota"
:quota-used="quotaUsed"
:custom-stepper-config="customStepperConfig"
@buy-clicked="onBuyClicked"
@add-cart="onAddCartClicked"
/>
```
#### Advanced Usage
```html
<van-sku
v-model="showCustomAction"
stepper-title="Stepper title"
:sku="sku"
:goods="goods"
:goods-id="goodsId"
:hide-stock="sku.hide_stock"
:quota="quota"
:quota-used="quotaUsed"
show-add-cart-btn
reset-stepper-on-hide
:initial-sku="initialSku"
@buy-clicked="onBuyClicked"
@add-cart="onAddCartClicked"
>
<!-- custom sku-header-price -->
<template slot="sku-header-price" slot-scope="props">
<div class="van-sku__goods-price">
<span class="van-sku__price-symbol"></span><span class="van-sku__price-num">{{ props.price }}</span>
</div>
</template>
<!-- custom sku actions -->
<template slot="sku-actions" slot-scope="props">
<div class="van-sku-actions">
<van-button bottom-action @click="onPointClicked">Button</van-button>
<!-- trigger sku inner event -->
<van-button type="primary" bottom-action @click="props.skuEventBus.$emit('sku:buy')">Button</van-button>
</div>
</template>
</van-sku>
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| v-model | Whether to show sku | `Boolean` | `false` |
| sku | Sku data | `Object` | - |
| goods | Goods info | `Object` | - |
| goods-id | Goods id | `String | Number` | - |
| hide-stock | Whether to hide stock | `Boolean` | `false` |
| show-add-cart-btn | Whether to show cart button | `Boolean` | `true` |
| quota | Quota (0 as no limit) | `Number` | `0` |
| quota-used | Used quota | `Number` | `0` |
| reset-stepper-on-hide | Whether to reset stepper when hide | `Boolean` | `false` |
| reset-selected-sku-on-hide | Whether to reset selected sku when hide | `Boolean` | `false` |
| disable-stepper-input | Whether to disable stepper input | `Boolean` | `false` |
| close-on-click-overlay | Whether to close sku popup when click overlay | `Boolean` | `false` |
| stepper-title | Quantity title | `String` | `Quantity` |
| custom-stepper-config | Custom stepper related config | `Object` | `{}` |
| message-config | Message related config | `Object` | `{}` |
| get-container | Return the mount node for sku | `() => HTMLElement` | - |
### Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| add-cart | Triggered when click cart button | data: Object |
| buy-clicked | Triggered when click buy button | data: Object |
### Methods
| Method | Description |
|-----------|-----------|
| getSkuData() | Get current sku data |
### Slot
| Name | Description |
|-----------|-----------|
| sku-header | Custom header |
| sku-header-price | Custom header price area |
| sku-body-top | Custom content before sku-group |
| sku-group | Custom sku |
| extra-sku-group | Extra custom content |
| sku-stepper | Custom stepper |
| sku-messages | Custom messages |
| sku-actions | Custom button actions |
#### Data Structure
#### Sku Data Structure
```javascript
sku: {
tree: [
{
k: 'Color',
v: [
{
id: '30349',
name: 'Red',
imgUrl: 'https://img.yzcdn.cn/1.jpg'
},
{
id: '1215',
name: 'Blue',
imgUrl: 'https://img.yzcdn.cn/2.jpg'
}
],
k_s: 's1'
}
],
list: [
{
id: 2259,
price: 100,
s1: '1215',
s2: '1193',
s3: '0',
stock_num: 110
}
],
price: '1.00',
stock_num: 227,
collection_id: 2261,
none_sku: false,
messages: [
{
datetime: '0',
multiple: '0',
name: 'Message',
type: 'text',
required: '1'
}
],
hide_stock: false
}
```
#### Goods Data Structure
```javascript
goods: {
title: 'Title',
picture: 'https://img.yzcdn.cn/1.jpg'
}
```
#### customStepperConfig Data Structure
```javascript
customStepperConfig: {
// custom quota text
quotaText: 'only 5 can buy',
// custom callback when over limit
handleOverLimit: (data) => {
const { action, limitType, quota, quotaUsed } = data;
if (action === 'minus') {
Toast('at least select one');
} else if (action === 'plus') {
// const { LIMIT_TYPE } = Sku.skuConstants;
if (limitType === LIMIT_TYPE.QUOTA_LIMIT) {
let msg = `Buy up to ${quota}`;
if (quotaUsed > 0) msg += `you already buy ${quotaUsed}`;
Toast(msg);
} else {
Toast('not enough stock');
}
}
}
}
```
#### messageConfig Data Structure
```javascript
messageConfig: {
// the upload image callback
uploadImg: () => {
return new Promise((resolve) => {
setTimeout(() => resolve('https://img.yzcdn.cn/upload_files/2017/02/21/FjKTOxjVgnUuPmHJRdunvYky9OHP.jpg!100x100.jpg'), 1000);
});
},
// max file size (MB)
uploadMaxSize: 3,
// placehold config
placeholderMap: {
text: 'xxx',
tel: 'xxx',
...
}
}
```
#### Event Params Data Structure
```javascript
skuData: {
goodsId: '946755',
messages: {
message_0: '12',
message_1: ''
},
cartMessages: {
'Message 1': 'xxxx'
},
selectedNum: 1,
selectedSkuComb: {
id: 2257,
price: 100,
s1: '30349',
s2: '1193',
s3: '0',
stock_num: 111
}
}
```
+267
View File
@@ -0,0 +1,267 @@
## Sku 商品购买组件
### 使用指南
```javascript
import { Sku } from 'vant';
Vue.use(Sku);
```
### 代码演示
#### 基础用法
```html
<van-sku
v-model="showBase"
:sku="sku"
:goods="goods"
:goods-id="goodsId"
:hide-stock="sku.hide_stock"
:quota="quota"
:quota-used="quotaUsed"
:reset-stepper-on-hide="resetStepperOnHide"
:reset-selected-sku-on-hide="resetSelectedSkuOnHide"
:close-on-click-overlay="closeOnClickOverlay"
:disable-stepper-input="disableStepperInput"
:message-config="messageConfig"
@buy-clicked="onBuyClicked"
@add-cart="onAddCartClicked"
/>
```
#### 自定义步进器相关配置
```html
<van-sku
v-model="showBase"
:sku="sku"
:goods="goods"
:goods-id="goodsId"
:hide-stock="sku.hide_stock"
:quota="quota"
:quota-used="quotaUsed"
:custom-stepper-config="customStepperConfig"
@buy-clicked="onBuyClicked"
@add-cart="onAddCartClicked"
/>
```
#### 高级用法
```html
<van-sku
v-model="showCustomAction"
stepper-title="我要买"
:sku="sku"
:goods="goods"
:goods-id="goodsId"
:hide-stock="sku.hide_stock"
:quota="quota"
:quota-used="quotaUsed"
show-add-cart-btn
reset-stepper-on-hide
:initial-sku="initialSku"
@buy-clicked="onBuyClicked"
@add-cart="onAddCartClicked"
>
<!-- 自定义 sku-header-price -->
<template slot="sku-header-price" slot-scope="props">
<div class="van-sku__goods-price">
<span class="van-sku__price-symbol"></span><span class="van-sku__price-num">{{ props.price }}</span>
</div>
</template>
<!-- 自定义 sku actions -->
<template slot="sku-actions" slot-scope="props">
<div class="van-sku-actions">
<van-button bottom-action @click="onPointClicked">积分兑换</van-button>
<!-- 直接触发 sku 内部事件,通过内部事件执行 onBuyClicked 回调 -->
<van-button type="primary" bottom-action @click="props.skuEventBus.$emit('sku:buy')">买买买</van-button>
</div>
</template>
</van-sku>
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| v-model | 是否显示sku | `Boolean` | `false` |
| sku | 商品sku数据 | `Object` | - |
| goods | 商品信息 | `Object` | - |
| goods-id | 商品id | `String | Number` | - |
| hide-stock | 是否显示商品剩余库存 | `Boolean` | `false` |
| show-add-cart-btn | 是否显示加入购物车按钮 | `Boolean` | `true` |
| quota | 限购数(0表示不限购) | `Number` | `0` |
| quota-used | 已经购买过的数量 | `Number` | `0` |
| reset-stepper-on-hide | 窗口隐藏时重置选择的商品数量 | `Boolean` | `false` |
| reset-selected-sku-on-hide | 窗口隐藏时重置已选择的sku | `Boolean` | `false` |
| disable-stepper-input | 是否禁用sku中stepper的input框 | `Boolean` | `false` |
| close-on-click-overlay | 点击popup的overlay后是否关闭弹窗 | `Boolean` | `false` |
| stepper-title | 数量选择组件左侧文案 | `String` | `购买数量` |
| custom-stepper-config | 步进器相关自定义配置 | `Object` | `{}` |
| message-config | 留言相关配置 | `Object` | `{}` |
| get-container | 指定挂载的 HTML 节点 | `() => HTMLElement` | - |
### Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| add-cart | 点击添加购物车回调 | skuData: Object |
| buy-clicked | 点击购买回调 | skuData: Object |
### 方法
| 函数 | 说明 |
|-----------|-----------|
| getSkuData() | 获取当前 skuData |
### Slot
Sku 组件默认划分好了若干区块,这些区块都定义成了 slot,可以按需进行替换。区块顺序见下表:
| 名称 | 说明 |
|-----------|-----------|
| sku-header | 商品信息展示区,包含商品图片、名称、价格等信息 |
| sku-header-price | 自定义sku头部价格展示 |
| sku-body-top | sku展示区上方的slot,无默认展示内容,按需使用 |
| sku-group | 商品sku展示区 |
| extra-sku-group | 额外商品sku展示区,一般用不到 |
| sku-stepper | 商品数量选择区 |
| sku-messages | 商品留言区 |
| sku-actions | 操作按钮区 |
### 数据结构
#### sku对象结构
```javascript
sku: {
// 所有sku规格类目与其值的从属关系,比如商品有颜色和尺码两大类规格,颜色下面又有红色和蓝色两个规格值。
// 可以理解为一个商品可以有多个规格类目,一个规格类目下可以有多个规格值。
tree: [
{
k: '颜色', // skuKeyName:规格类目名称
v: [
{
id: '30349', // skuValueId:规格值 id
name: '红色', // skuValueName:规格值名称
imgUrl: 'https://img.yzcdn.cn/1.jpg' // 规格类目图片,只有第一个规格类目可以定义图片
},
{
id: '1215',
name: '蓝色',
imgUrl: 'https://img.yzcdn.cn/2.jpg'
}
],
k_s: 's1' // skuKeyStrsku 组合列表(下方 list)中当前类目对应的 key 值,value 值会是从属于当前类目的一个规格值 id
}
],
// 所有 sku 的组合列表,比如红色、M 码为一个 sku 组合,红色、S 码为另一个组合
list: [
{
id: 2259, // skuId,下单时后端需要
price: 100, // 价格(单位分)
s1: '1215', // 规格类目 k_s 为 s1 的对应规格值 id
s2: '1193', // 规格类目 k_s 为 s2 的对应规格值 id
s3: '0', // 最多包含3个规格值,为0表示不存在该规格
stock_num: 110 // 当前 sku 组合对应的库存
}
],
price: '1.00', // 默认价格(单位元)
stock_num: 227, // 商品总库存
collection_id: 2261, // 无规格商品 skuId 取 collection_id,否则取所选 sku 组合对应的 id
none_sku: false, // 是否无规格商品
messages: [
{
// 商品留言
datetime: '0', // 留言类型为 time 时,是否含日期。'1' 表示包含
multiple: '0', // 留言类型为 text 时,是否多行文本。'1' 表示多行
name: '留言', // 留言名称
type: 'text', // 留言类型,可选: id_no(身份证), text, tel, date, time, email
required: '1' // 是否必填 '1' 表示必填
}
],
hide_stock: false // 是否隐藏剩余库存
}
```
#### goods 对象结构
```javascript
goods: {
// 商品标题
title: '测试商品',
// 默认商品 sku 缩略图
picture: 'https://img.yzcdn.cn/1.jpg'
}
```
#### customStepperConfig 对象结构
```javascript
customStepperConfig: {
// 自定义限购文案
quotaText: '每次限购xxx件',
// 自定义步进器超过限制时的回调
handleOverLimit: (data) => {
const { action, limitType, quota, quotaUsed } = data;
if (action === 'minus') {
Toast('至少选择一件商品');
} else if (action === 'plus') {
// const { LIMIT_TYPE } = Sku.skuConstants;
if (limitType === LIMIT_TYPE.QUOTA_LIMIT) {
let msg = `单次限购${quota}`;
if (quotaUsed > 0) msg += `,您已购买${quotaUsed}`;
Toast(msg);
} else {
Toast('库存不够了~~');
}
}
}
}
```
#### messageConfig Data Structure
```javascript
messageConfig: {
// 图片上传回调,需要返回一个promise,promise正确执行的结果需要是一个图片url
uploadImg: () => {
return new Promise((resolve) => {
setTimeout(() => resolve('https://img.yzcdn.cn/upload_files/2017/02/21/FjKTOxjVgnUuPmHJRdunvYky9OHP.jpg!100x100.jpg'), 1000);
});
},
// 最大上传体积 (MB)
uploadMaxSize: 3,
// placehold配置
placeholderMap: {
text: 'xxx',
tel: 'xxx',
...
}
}
```
#### 添加购物车和点击购买回调函数接收的 skuData 对象结构
```javascript
skuData: {
// 商品 id
goodsId: '946755',
// 留言信息
messages: {
message_0: '12',
message_1: ''
},
// 另一种格式的留言,key 不同
cartMessages: {
'留言1': 'xxxx'
},
// 选择的商品数量
selectedNum: 1,
// 选择的 sku 组合
selectedSkuComb: {
id: 2257,
price: 100,
s1: '30349',
s2: '1193',
s3: '0',
stock_num: 111
}
}
```
+66
View File
@@ -0,0 +1,66 @@
## Slider
### Install
``` javascript
import { Slider } from 'vant';
Vue.use(Slider);
```
### Usage
#### Basic Usage
```html
<van-slider v-model="value" @change="onChange" />
```
```js
export default {
data() {
return {
value: 50
};
},
methods: {
onChange(value) {
this.$toast('Current value' + value);
}
}
};
```
#### Range
```html
<van-slider v-model="value" :min="10" :max="90" />
```
#### Disabled
```html
<van-slider v-model="value" disabled />
```
#### Step size
```html
<van-slider v-model="value" :step="10" bar-height="4px" />
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|-------------|
| value | Current value | `Number` | `0` |
| disabled | Whether to disable slider | `Boolean` | `false` |
| max | Max value | `Number` | `100` |
| min | Min value | `Number` | `0` |
| step | Step size | `Number` | `1` |
| bar-height | Height of bar | `String` | `2px` |
### Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| change | Triggered after value change | value: current rate |
+65
View File
@@ -0,0 +1,65 @@
## Slider 滑块
### 使用指南
``` javascript
import { Slider } from 'vant';
Vue.use(Slider);
```
#### 基本用法
```html
<van-slider v-model="value" @change="onChange" />
```
```js
export default {
data() {
return {
value: 50
};
},
methods: {
onChange(value) {
this.$toast('当前值:' + value);
}
}
};
```
#### 指定选择范围
```html
<van-slider v-model="value" :min="10" :max="90" />
```
#### 禁用
```html
<van-slider v-model="value" disabled />
```
#### 指定步长
```html
<van-slider v-model="value" :step="10" bar-height="4px" />
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| value | 当前进度百分比 | `Number` | `0` |
| disabled | 是否禁用滑块 | `Boolean` | `false` |
| max | 最大值 | `Number` | `100` |
| min | 最小值 | `Number` | `0` |
| step | 步长 | `Number` | `1` |
| bar-height | 进度条高度 | `String` | `2px` |
### Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| change | 进度值改变后触发 | value: 当前进度 |
+66
View File
@@ -0,0 +1,66 @@
## Stepper
### Install
``` javascript
import { Stepper } from 'vant';
Vue.use(Stepper);
```
### Usage
#### Basic Usage
```html
<van-stepper v-model="value" />
```
```javascript
export default {
data() {
return {
value: 1
}
}
}
```
#### Disabled
```html
<van-stepper v-model="value" disabled />
```
#### Advanced Usage
```html
<van-stepper
v-model="value"
integer
:min="5"
:max="40"
:step="2"
:default-value="9"
/>
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| min | Min value | `String | Number` | `1` |
| max | Max value | `String | Number` | - |
| default-value | Default value | `String | Number` | `1` |
| step | Value change step | `String | Number` | `1` |
| integer | Whether to allow only integers | `Boolean` | `false` |
| disabled | Disable value change | `Boolean` | `false` |
| disable-input | Disable input | `Boolean` | `false` |
### Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| change | Triggered when value change | value: current value |
| overlimit | Triggered when click disabled button | - |
| plus | Triggered when click plus button | - |
| minus | Triggered when click minus button | - |
+69
View File
@@ -0,0 +1,69 @@
## Stepper 步进器
### 使用指南
``` javascript
import { Stepper } from 'vant';
Vue.use(Stepper);
```
### 代码演示
#### 基础用法
```html
<van-stepper v-model="value" />
```
```javascript
export default {
data() {
return {
value: 1
}
}
}
```
#### 禁用状态
通过设置`disabled`属性来禁用 stepper
```html
<van-stepper v-model="value" disabled />
```
#### 高级用法
默认是每次加减为1,可以对组件设置`step`、`min`、`max`、`default-value`属性
```html
<van-stepper
v-model="value"
integer
:min="5"
:max="40"
:step="2"
:default-value="9"
/>
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| min | 最小值 | `String | Number` | `1` |
| max | 最大值 | `String | Number` | - |
| default-value | 默认值 | `String | Number` | `1` |
| step | 步数 | `String | Number` | `1` |
| integer | 是否只允许输入整数 | `Boolean` | `false` |
| disabled | 是否禁用 | `Boolean` | `false` |
| disable-input | 是否禁用input框 | `Boolean` | `false` |
### Event
| 事件名称 | 说明 | 回调参数 |
|-----------|-----------|-----------|
| change | 当绑定值变化时触发的事件 | 当前组件的值 |
| overlimit | 点击不可用的按钮时触发 | - |
| plus | 点击增加按钮时触发 | - |
| minus | 点击减少按钮时触发 | - |
+85
View File
@@ -0,0 +1,85 @@
## Steps
### Install
``` javascript
import { Step, Steps } from 'vant';
Vue.use(Step).use(Steps);
```
### Usage
#### Basic Usage
```html
<van-steps :active="active">
<van-step>Step1</van-step>
<van-step>Step2</van-step>
<van-step>Step3</van-step>
<van-step>Step4</van-step>
</van-steps>
```
```javascript
export default {
data() {
return {
active: 1
};
}
}
```
#### Description
```html
<van-steps
:active="active"
icon="logistics"
title="Title"
description="Description"
>
<van-step>Step1</van-step>
<van-step>Step2</van-step>
<van-step>Step3</van-step>
<van-step>Step4</van-step>
</van-steps>
```
#### Vertical Steps
```html
<van-steps direction="vertical" :active="0" active-color="#f60">
<van-step>
<h3>【City】Status1</h3>
<p>2016-07-12 12:40</p>
</van-step>
<van-step>
<h3>【City】Status2</h3>
<p>2016-07-11 10:00</p>
</van-step>
<van-step>
<h3>【City】Status3</h3>
<p>2016-07-10 09:30</p>
</van-step>
</van-steps>
```
### Steps API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| active | Active step | `Number` | 0 |
| icon | Action step icon | `String` | - |
| icon-class | Icon class | `String` | - |
| title | Title | `String` | - |
| description | Description | `String` | - |
| direction | Can be set to `horizontal` `vertical` | `String` | `horizontal` |
| active-color | Active step color | `String` | `#06bf04` |
### Steps Slot
| Name | Description |
|-----------|-----------|
| icon | Custom icon |
| message-extra | Extra content |
+88
View File
@@ -0,0 +1,88 @@
## Steps 步骤条
### 使用指南
``` javascript
import { Step, Steps } from 'vant';
Vue.use(Step).use(Steps);
```
### 代码演示
#### 基础用法
```html
<van-steps :active="active">
<van-step>买家下单</van-step>
<van-step>商家接单</van-step>
<van-step>买家提货</van-step>
<van-step>交易完成</van-step>
</van-steps>
```
```javascript
export default {
data() {
return {
active: 1
};
}
}
```
#### 描述信息
通过`title`和`description`属性来定义描述信息信息
```html
<van-steps
:active="active"
icon="logistics"
title="标题"
description="描述信息"
>
<van-step>买家下单</van-step>
<van-step>商家接单</van-step>
<van-step>买家提货</van-step>
<van-step>交易完成</van-step>
</van-steps>
```
#### 竖向步骤条
可以通过设置`direction`属性来改变步骤条的显示方式
```html
<van-steps direction="vertical" :active="0" active-color="#f60">
<van-step>
<h3>【城市】物流状态1</h3>
<p>2016-07-12 12:40</p>
</van-step>
<van-step>
<h3>【城市】物流状态2</h3>
<p>2016-07-11 10:00</p>
</van-step>
<van-step>
<h3>快件已发货</h3>
<p>2016-07-10 09:30</p>
</van-step>
</van-steps>
```
### Steps API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| active | 当前步骤 | `Number` | 0 |
| title | 描述栏标题 | `String` | - |
| description | 描述栏文字 | `String` | - |
| icon | 描述栏图标 | `String` | - |
| icon-class | 图标额外类名 | `String` | - |
| direction | 显示方向,可选值为 `horizontal` `vertical` | `String` | `horizontal` |
| active-color | 激活状态颜色 | `String` | `#06bf04` |
### Steps Slot
| Name | 说明 |
|-----------|-----------|
| icon | 自定义icon区域 |
| message-extra | 状态栏添加额外的元素 |
+87
View File
@@ -0,0 +1,87 @@
## SubmitBar
### Install
``` javascript
import { SubmitBar } from 'vant';
Vue.use(SubmitBar);
```
### Usage
#### Basic Usage
```html
<van-submit-bar
:price="3050"
button-text="Submit"
@submit="onSubmit"
/>
```
#### Disabled
`submit` event will not triggerd when disabled.
```html
<van-submit-bar
disabled
:price="3050"
button-text="Submit"
tip="Some tips"
@submit="onSubmit"
/>
```
#### Loading
`submit` event will not triggerd when loading.
```html
<van-submit-bar
loading
:price="3050"
button-text="Submit"
@submit="onSubmit"
/>
```
#### Advanced Usage
Use slot to add custom contents.
```html
<van-submit-bar
:price="3050"
button-text="Submit"
@submit="onSubmit"
>
<van-checkbox v-model="checked">Check</van-checkbox>
<span slot="tip">
Some tips, <span @click="onClickEditAddress">Link</span>
</span>
</van-submit-bar>
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| price | Price | `Number` | - |
| label | Price label | `String` | `合计:` |
| button-text | Button text | `String` | - |
| button-type | Button type | `String` | `danger` |
| tip | Tip | `String` | - |
| disabled | Whether to disable button | `Boolean` | `false` |
| loading | Whether to show loading icon | `Boolean` | `false` |
| currency | Currency symbol | `String` | `¥` |
### Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| submit | Triggerd when click submit button | - |
### Slot
| Name | Description |
|-----------|-----------|
| default | Custom left content |
| tip | Custom tips |
+87
View File
@@ -0,0 +1,87 @@
## SubmitBar 提交订单栏
### 使用指南
``` javascript
import { SubmitBar } from 'vant';
Vue.use(SubmitBar);
```
### 代码演示
#### 基础用法
```html
<van-submit-bar
:price="3050"
button-text="提交订单"
@submit="onSubmit"
/>
```
#### 禁用状态
禁用状态下不会触发`submit`事件
```html
<van-submit-bar
disabled
:price="3050"
button-text="提交订单"
tip="您的收货地址不支持同城送, 我们已为您推荐快递"
@submit="onSubmit"
/>
```
#### 加载状态
加载状态下不会触发`submit`事件
```html
<van-submit-bar
loading
:price="3050"
button-text="提交订单"
@submit="onSubmit"
/>
```
#### 高级用法
通过 slot 插入自定义内容
```html
<van-submit-bar
:price="3050"
button-text="提交订单"
@submit="onSubmit"
>
<van-checkbox v-model="checked">全选</van-checkbox>
<span slot="tip">
您的收货地址不支持同城送, <span>修改地址</span>
</span>
</van-submit-bar>
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| price | 价格(单位分) | `Number` | - |
| label | 价格文案 | `String` | `合计:` |
| button-text | 按钮文字 | `String` | - |
| button-type | 按钮类型 | `String` | `danger` |
| tip | 提示文案 | `String` | - |
| disabled | 是否禁用按钮 | `Boolean` | `false` |
| loading | 是否显示加载中的按钮 | `Boolean` | `false` |
| currency | 货币符号 | `String` | `¥` |
### Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| submit | 按钮点击事件回调 | - |
### Slot
| 名称 | 说明 |
|-----------|-----------|
| default | 自定义订单栏左侧内容 |
| tip | 提示文案中的额外操作和说明 |
+96
View File
@@ -0,0 +1,96 @@
## Swipe
### Install
``` javascript
import { Swipe, SwipeItem } from 'vant';
Vue.use(Swipe).use(SwipeItem);
```
### Usage
#### Basic Usage
Use `autoplay` prop to set autoplay interval
```html
<van-swipe :autoplay="3000">
<van-swipe-item>1</van-swipe-item>
<van-swipe-item>2</van-swipe-item>
<van-swipe-item>3</van-swipe-item>
<van-swipe-item>4</van-swipe-item>
</van-swipe>
```
#### Image Lazyload
Use [Lazyload](#/en-US/lazyload) component to lazyload image
```html
<van-swipe>
<van-swipe-item v-for="(image, index) in images" :key="index">
<img v-lazy="image" />
</van-swipe-item>
</van-swipe>
```
```javascript
export default {
data() {
return {
images: [
'https://img.yzcdn.cn/1.jpg',
'https://img.yzcdn.cn/2.jpg'
]
}
}
}
```
#### change event
```html
<van-swipe @change="onChange">
<van-swipe-item>1</van-swipe-item>
<van-swipe-item>2</van-swipe-item>
<van-swipe-item>3</van-swipe-item>
<van-swipe-item>4</van-swipe-item>
</van-swipe>
```
```js
export default {
methods: {
onChange(index) {
Toast('Current Swipe index:' + index);
}
}
}
```
#### Vertical Scrolling
```html
<van-swipe :autoplay="3000" vertical>
<van-swipe-item>1</van-swipe-item>
<van-swipe-item>2</van-swipe-item>
<van-swipe-item>3</van-swipe-item>
<van-swipe-item>4</van-swipe-item>
</van-swipe>
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| autoplay | Autoplay interval (ms) | `Number` | - |
| duration | Animation duration (ms) | `Number` | `500` |
| loop | Whether to enable loop | `Boolean` | `true` |
| vertical | Vertical Scrolling | `Boolean` | `false` |
| touchable | Whether touchable | `Boolean` | `true` |
| show-indicators | Whether to show indocators | `Boolean` | `true` |
| initial-swipe | Index of initial swipe, start from 0 | `Number` | `0` |
### Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| change | Triggered when current swipe change | index: index of current swipe |
+96
View File
@@ -0,0 +1,96 @@
## Swipe 轮播
### 使用指南
``` javascript
import { Swipe, SwipeItem } from 'vant';
Vue.use(Swipe).use(SwipeItem);
```
### 代码演示
#### 基础用法
通过`autoplay`属性设置自动轮播间隔
```html
<van-swipe :autoplay="3000">
<van-swipe-item>1</van-swipe-item>
<van-swipe-item>2</van-swipe-item>
<van-swipe-item>3</van-swipe-item>
<van-swipe-item>4</van-swipe-item>
</van-swipe>
```
#### 图片懒加载
配合 [Lazyload](#/zh-CN/lazyload) 组件实现图片懒加载
```html
<van-swipe :autoplay="3000">
<van-swipe-item v-for="(image, index) in images" :key="index">
<img v-lazy="image" />
</van-swipe-item>
</van-swipe>
```
```javascript
export default {
data() {
return {
images: [
'https://img.yzcdn.cn/1.jpg',
'https://img.yzcdn.cn/2.jpg'
]
}
}
}
```
#### 监听 change 事件
```html
<van-swipe @change="onChange">
<van-swipe-item>1</van-swipe-item>
<van-swipe-item>2</van-swipe-item>
<van-swipe-item>3</van-swipe-item>
<van-swipe-item>4</van-swipe-item>
</van-swipe>
```
```js
export default {
methods: {
onChange(index) {
Toast('当前 Swipe 索引:' + index);
}
}
}
```
#### 纵向滚动
```html
<van-swipe :autoplay="3000" vertical>
<van-swipe-item>1</van-swipe-item>
<van-swipe-item>2</van-swipe-item>
<van-swipe-item>3</van-swipe-item>
<van-swipe-item>4</van-swipe-item>
</van-swipe>
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| autoplay | 自动轮播间隔,单位为 ms | `Number` | - |
| duration | 动画时长,单位为 ms | `Number` | `500` |
| loop | 是否开启循环播放 | `Boolean` | `true` |
| vertical | 是否为纵向滚动 | `Boolean` | `false` |
| touchable | 是否可以通过手势滑动 | `Boolean` | `true` |
| show-indicators | 是否显示指示器 | `Boolean` | `true` |
| initial-swipe | 初始位置,从 0 开始算 | `Number` | `0` |
### 事件
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| change | 每一页轮播结束后触发 | index, 当前页的索引 |
+64
View File
@@ -0,0 +1,64 @@
## SwitchCell
`SwitchCell` component is an encapsulation of `Switch` and `Cell`.
### Install
``` javascript
import { SwitchCell } from 'vant';
Vue.use(SwitchCell);
```
### Usage
#### Basic Usage
```html
<van-cell-group>
<van-switch-cell v-model="checked" title="Title" />
</van-cell-group>
```
```javascript
export default {
data() {
return {
checked: true
}
}
}
```
#### Disabled
use `disabled` property to disable the component
```html
<van-cell-group>
<van-switch-cell v-model="checked" disabled title="Title" />
</van-cell-group>
```
#### Loading
use `loading` property to keep component in loading state
```html
<van-cell-group>
<van-switch-cell v-model="checked" loading title="Title" />
</van-cell-group>
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| v-model | on-off state of the switch | `Boolean` | - |
| title | the leftside title | `String` | `''` |
| loading | whether the component is in loading state | `Boolean` | `false` |
| disabled | whether to disable the component | `Boolean` | `false` |
### Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| change | triggered when the on-off state is changed | checked: switch is on or not |
+64
View File
@@ -0,0 +1,64 @@
## SwitchCell 开关单元格
`SwitchCell`组件是对`Switch``Cell`组件的封装
### 使用指南
``` javascript
import { SwitchCell } from 'vant';
Vue.use(SwitchCell);
```
### 代码演示
#### 基础用法
```html
<van-cell-group>
<van-switch-cell v-model="checked" title="标题" />
</van-cell-group>
```
```javascript
export default {
data() {
return {
checked: true
}
}
}
```
#### 禁用状态
通过`disabled`属性可以将组件设置为禁用状态
```html
<van-cell-group>
<van-switch-cell v-model="checked" disabled title="标题" />
</van-cell-group>
```
#### 加载状态
通过`loading`属性可以将组件设置为加载状态
```html
<van-cell-group>
<van-switch-cell v-model="checked" loading title="标题" />
</van-cell-group>
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| v-model | 开关状态 | `Boolean` | - |
| title | 左侧标题 | `String` | `''` |
| loading | 是否为加载状态 | `Boolean` | `false` |
| disabled | 是否为禁用状态 | `Boolean` | `false` |
### Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| change | 开关状态切换回调 | checked: 是否选中开关 |
+81
View File
@@ -0,0 +1,81 @@
## Switch
### Install
``` javascript
import { Switch } from 'vant';
Vue.use(Switch);
```
### Usage
#### Basic Usage
```html
<van-switch v-model="checked" />
```
```javascript
export default {
data() {
return {
checked: true
};
}
};
```
#### Disabled
```html
<van-switch v-model="checked" disabled />
```
#### Loading
```html
<van-switch v-model="checked" loading />
```
#### Advanced usage
```html
<van-switch :value="checked" size="36px" @input="onInput" />
```
```js
export default {
data() {
return {
checked: true
};
},
methods: {
onInput(checked) {
Dialog.confirm({
title: 'Confirm',
message: 'Are you sure to toggle switch?'
}).then(() => {
this.checked = checked;
});
}
}
};
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| v-model | Check status of Switch | `Boolean` | `false` |
| loading | Whether to show loading icon | `Boolean` | `false` |
| disabled | Whether to disable switch | `Boolean` | `false` |
| size | Size of switch | `String` | `30px` |
### Event
| Event | Description | Parameters |
|-----------|-----------|-----------|
| change | Triggered when check status changed | checked: is switch checked |
+77
View File
@@ -0,0 +1,77 @@
## Switch 开关
### 使用指南
``` javascript
import { Switch } from 'vant';
Vue.use(Switch);
```
### 代码演示
#### 基础用法
```html
<van-switch v-model="checked" />
```
```javascript
export default {
data() {
return {
checked: true
};
}
};
```
#### 禁用状态
```html
<van-switch v-model="checked" disabled />
```
#### 加载状态
```html
<van-switch v-model="checked" loading />
```
#### 高级用法
```html
<van-switch :value="checked" size="36px" @input="onInput" />
```
```js
export default {
data() {
return {
checked: true
};
},
methods: {
onInput(checked) {
Dialog.confirm({
title: '提醒',
message: '是否切换开关?'
}).then(() => {
this.checked = checked;
});
}
}
};
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| v-model | 开关选中状态 | `Boolean` | `false` |
| loading | 是否为加载状态 | `Boolean` | `false` |
| disabled | 是否为禁用状态 | `Boolean` | `false` |
| size | 开关尺寸 | `String` | `30px` |
### Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| change | 开关状态切换回调 | checked: 是否选中开关 |
+168
View File
@@ -0,0 +1,168 @@
## Tab
### Install
``` javascript
import { Tab, Tabs } from 'vant';
Vue.use(Tab).use(Tabs);
```
### Usage
#### Basic Usage
The first tab is actived by default, you can set `v-model` to active specified tab.
```html
<van-tabs v-model="active">
<van-tab v-for="index in 4" :title="'tab' + index">
content of tab {{ index }}
</van-tab>
</van-tabs>
```
```js
export default {
data() {
return {
active: 2
};
}
}
```
#### Swipe Tabs
By default more than 4 tabs, you can scroll through the tabs. You can set `swipe-threshold` attribute to customize threshold number.
```html
<van-tabs>
<van-tab v-for="index in 8" :title="'tab' + index">
content of tab {{ index }}
</van-tab>
</van-tabs>
```
#### Disabled Tab
You can set `disabled` attribute on the corresponding `van-tab`.
```html
<van-tabs @disabled="onClickDisabled">
<van-tab v-for="index in 4" :title="'tab' + index" :disabled="index === 2">
content of tab {{ index }}
</van-tab>
</van-tabs>
```
```javascript
export default {
methods: {
onClickDisabled(index, title) {
this.$toast(title + ' is disabled');
}
}
};
```
#### Card Style
Tabs styled as cards.
```html
<van-tabs type="card">
<van-tab v-for="index in 4" :title="'tab' + index">
content of tab {{ index }}
</van-tab>
</van-tabs>
```
#### Click Event
```html
<van-tabs @click="onClick">
<van-tab v-for="index in 4" :title="'tab' + index">
content of tab {{ index }}
</van-tab>
</van-tabs>
```
```javascript
export default {
methods: {
onClick(index, title) {
this.$toast(title);
}
}
};
```
#### Sticky
In sticky mode, the tab will be fixed to top when scroll to top
```html
<van-tabs v-model="active" sticky>
<van-tab v-for="index in 4" :title="'tab ' + index">
content {{ index }}
</van-tab>
</van-tabs>
```
#### Custom title
Use title slot to custom tab title
```html
<van-tabs v-model="active">
<van-tab v-for="index in 2">
<div slot="title">
<van-icon name="more-o" />tab
</div>
content {{ index }}
</van-tab>
</van-tabs>
```
#### Swipeable
In swipeable mode, you can switch tabs with swipe gestrue in the content
```html
<van-tabs v-model="active" swipeable>
<van-tab v-for="index in 4" :title="'tab ' + index">
content {{ index }}
</van-tab>
</van-tabs>
```
### Tabs API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| v-model | Index of active tab | `String` `Number` | `0` |
| type | Can be set to `line` `card` | `String` | `line` |
| duration | Toggle tab's animation time | `Number` | `0.2` | - |
| line-width | Width of tab line (px) | `Number` | Width of active tab |
| swipe-threshold | Set swipe tabs threshold | `Number` | `4` | - |
| sticky | Whether to use sticky mode | `Boolean` | `false` |
| swipeable | Whether to switch tabs with swipe gestrue in the content | `Boolean` | `false` |
### Tab API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| title | Title | `String` | - |
| disabled | Whether to disable tab | `Boolean` | `false` |
### Tab Slot
| name | Description |
|-----------|-----------|
| - | Content |
| title | Custom tab |
### Tabs Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| click | Triggered when click tab | indexindex of current tabtitle: tab title |
| disabled | Triggered when click disabled tab | indexindex of current tab, title: tab title |
+171
View File
@@ -0,0 +1,171 @@
## Tab 标签页
### 使用指南
``` javascript
import { Tab, Tabs } from 'vant';
Vue.use(Tab).use(Tabs);
```
### 代码演示
#### 基础用法
默认情况下启用第一个 tab,可以通过`v-model`绑定当前激活的标签索引
```html
<van-tabs v-model="active">
<van-tab v-for="index in 4" :title="'选项 ' + index">
内容 {{ index }}
</van-tab>
</van-tabs>
```
```js
export default {
data() {
return {
active: 2
};
}
}
```
#### 横向滚动
默认情况下多于4个tab时,可以横向滚动tab。可以通过设置`swipe-threshold`这个阙值,多于这个阙值时,tab就会支持横向滚动。
```html
<van-tabs>
<van-tab v-for="index in 8" :title="'选项 ' + index">
内容 {{ index }}
</van-tab>
</van-tabs>
```
#### 禁用标签
在对应的`van-tab`上设置`disabled`属性即可。如果需要监听禁用事件,可以在`van-tabs`上监听`disabled`事件。
```html
<van-tabs @disabled="onClickDisabled">
<van-tab v-for="index in 4" :title="'选项 ' + index" :disabled="index === 2">
内容 {{ index }}
</van-tab>
</van-tabs>
```
```javascript
export default {
methods: {
onClickDisabled(index, title) {
this.$toast(title + '已被禁用');
}
}
};
```
#### 样式风格
`Tabs`目前有两种样式:`line`和`card`,默认为`line`样式,也就上面基础用法中的样式,你可以在`van-tabs`上设置`type`为`card`改为card样式。
```html
<van-tabs type="card">
<van-tab v-for="index in 4" :title="'选项 ' + index">
内容 {{ index }}
</van-tab>
</van-tabs>
```
#### 点击事件
可以在`van-tabs`上绑定`click`事件,事件传参为标签对应的索引和标题
```html
<van-tabs @click="onClick">
<van-tab v-for="index in 4" :title="'选项 ' + index">
内容 {{ index }}
</van-tab>
</van-tabs>
```
```javascript
export default {
methods: {
onClick(index, title) {
this.$toast(title);
}
}
};
```
#### 粘性布局
通过`sticky`属性可以开启粘性布局,粘性布局下,当 Tab 滚动到顶部时会自动吸顶
```html
<van-tabs v-model="active" sticky>
<van-tab v-for="index in 4" :title="'选项 ' + index">
内容 {{ index }}
</van-tab>
</van-tabs>
```
#### 自定义标签
通过 title slot 可以自定义标签内容
```html
<van-tabs v-model="active">
<van-tab v-for="index in 2">
<div slot="title">
<van-icon name="more-o" />选项
</div>
内容 {{ index }}
</van-tab>
</van-tabs>
```
#### 滑动切换
通过`swipeable`属性可以开启滑动切换tab
```html
<van-tabs v-model="active" swipeable>
<van-tab v-for="index in 4" :title="'选项 ' + index">
内容 {{ index }}
</van-tab>
</van-tabs>
```
### Tabs API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| v-model | 当前激活标签的索引 | `String` `Number` | `0` |
| type | 样式类型,可选值为 `line` `card` | `String` | `line` |
| duration | 切换 tab 的动画时间 | `Number` | `0.2` |
| line-width | 底部条宽度 (px) | `Number` | 与当前标签等宽 |
| swipe-threshold | 滚动阀值,设置 Tab 超过多少个可滚动 | `Number` | `4` |
| sticky | 是否使用粘性定位布局 | `Boolean` | `false` |
| swipeable | 是否可以滑动内容切换 | `Boolean` | `false` |
### Tab API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| title | 标题 | `String` | - |
| disabled | 是否禁用标签 | `Boolean` | `false` |
### Tab Slot
| 名称 | 说明 |
|-----------|-----------|
| - | 标签页内容 |
| title | 自定义标签 |
### Tabs Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| click | 点击标签时触发 | index:标签索引,title:标题 |
| disabled | 点击被禁用的标签时触发 | index:标签索引,title:标题 |
+90
View File
@@ -0,0 +1,90 @@
## Tabbar
### Install
``` javascript
import { Tabbar, TabbarItem } from 'vant';
Vue.use(Tabbar).use(TabbarItem);
```
### Usage
#### Basic Usage
```html
<van-tabbar v-model="active">
<van-tabbar-item icon="shop">Tab</van-tabbar-item>
<van-tabbar-item icon="chat" dot>Tab</van-tabbar-item>
<van-tabbar-item icon="records" info="5">Tab</van-tabbar-item>
<van-tabbar-item icon="gold-coin" info="20">Tab</van-tabbar-item>
</van-tabbar>
```
```javascript
export default {
data() {
return {
active: 0
}
}
}
```
#### Custom icon
Use `icon` slot to custom icon
```html
<van-tabbar v-model="active">
<van-tabbar-item icon="shop">
<span>Custom</span>
<template slot="icon" slot-scope="props">
<img :src="props.active ? icon.active : icon.normal" />
</template>
</van-tabbar-item>
<van-tabbar-item icon="chat">Tab</van-tabbar-item>
<van-tabbar-item icon="records">Tab</van-tabbar-item>
</van-tabbar>
```
```javascript
export default {
data() {
return {
active: 0,
icon: {
normal: '//img.yzcdn.cn/1.png',
active: '//img.yzcdn.cn/2.png'
}
}
}
}
```
### Tabbar API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| v-model | Index of current tab | `Number` | - |
### Tabbar Event
| Event | Description | Arguments |
|-----------|-----------|-----------|
| change | Triggered when change active tab | active: index of current tab |
### TabbarItem API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| icon | Icon name | `String` | - |
| dot | Whether to show red dot | `Boolean` | - |
| info | Info message | `String | Number` | - |
| url | Link | `String` | - |
| to | Target route of the link, same as to of `vue-router` | `String | Object` | - |
| replace | If true, the navigation will not leave a history record | `String` | `false` |
### TabbarItem Slot
| Name | Description | Scope |
|-----------|-----------|-----------|
| icon | Custom icon | active |
+94
View File
@@ -0,0 +1,94 @@
## Tabbar 标签栏
### 使用指南
``` javascript
import { Tabbar, TabbarItem } from 'vant';
Vue.use(Tabbar).use(TabbarItem);
```
### 代码演示
#### 基础用法
```html
<van-tabbar v-model="active">
<van-tabbar-item icon="shop">标签</van-tabbar-item>
<van-tabbar-item icon="chat" dot>标签</van-tabbar-item>
<van-tabbar-item icon="records" info="5">标签</van-tabbar-item>
<van-tabbar-item icon="gold-coin" info="20">标签</van-tabbar-item>
</van-tabbar>
```
```javascript
export default {
data() {
return {
active: 0
}
}
}
```
#### 自定义图标
通过 icon slot 自定义图标
```html
<van-tabbar v-model="active">
<van-tabbar-item icon="shop">
<span>自定义</span>
<template slot="icon" slot-scope="props">
<img :src="props.active ? icon.active : icon.normal" />
</template>
</van-tabbar-item>
<van-tabbar-item icon="chat">标签</van-tabbar-item>
<van-tabbar-item icon="records">标签</van-tabbar-item>
</van-tabbar>
```
```javascript
export default {
data() {
return {
active: 0,
icon: {
normal: '//img.yzcdn.cn/1.png',
active: '//img.yzcdn.cn/2.png'
}
}
}
}
```
### Tabbar API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| v-model | 当前选中标签的索引 | `Number` | - |
### Tabbar Event
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| change | 切换标签时触发 | active: 当前选中标签 |
### TabbarItem API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-----------|
| icon | 图标名称 (可选值见 Icon 组件) | `String` | - |
| dot | 是否显示小红点 | `Boolean` | - |
| info | 图标右上角提示信息 | `String | Number` | - |
| url | 跳转链接 | `String` | - |
| to | 路由跳转对象,同 `vue-router` 的 to | `String | Object` | - |
| replace | 跳转时是否替换当前 history | `String` | `false` |
### TabbarItem Slot
| Name | 描述 | Scope |
|-----------|-----------|-----------|
| icon | 自定义icon | active |
+51
View File
@@ -0,0 +1,51 @@
## Tag
### Install
``` javascript
import { Tag } from 'vant';
Vue.use(Tag);
```
### Usage
#### Basic Usage
```html
<van-tag>Tag</van-tag>
<van-tag type="danger">Tag</van-tag>
<van-tag type="success">Tag</van-tag>
<van-tag type="primary">Tag</van-tag>
```
#### Plain style
```html
<van-tag plain>Tag</van-tag>
<van-tag plain type="danger">Tag</van-tag>
<van-tag plain type="primary">Tag</van-tag>
<van-tag plain type="success">Tag</van-tag>
```
#### Mark style
```html
<van-tag mark>Tag</van-tag>
<van-tag mark type="danger">Tag</van-tag>
<van-tag mark type="primary">Tag</van-tag>
<van-tag mark type="success">Tag</van-tag>
```
### API
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| type | Type, can be set to `primary` `success` `danger` | `String` | `''`|
| plain | Whether to be plain style | `Boolean` | `false` |
| mark | Wtether to be mark style | `Boolean` | `false` |
### Slot
| name | Description |
|-----------|-----------|
| - | Default slot |
+54
View File
@@ -0,0 +1,54 @@
## Tag 标记
### 使用指南
``` javascript
import { Tag } from 'vant';
Vue.use(Tag);
```
### 代码演示
#### 基础用法
通过 type 属性控制 Tag 颜色,默认为灰色
```html
<van-tag>标签</van-tag>
<van-tag type="danger">标签</van-tag>
<van-tag type="success">标签</van-tag>
<van-tag type="primary">标签</van-tag>
```
#### 空心样式
设置`plain`属性设置为空心样式
```html
<van-tag plain>标签</van-tag>
<van-tag plain type="danger">标签</van-tag>
<van-tag plain type="primary">标签</van-tag>
<van-tag plain type="success">标签</van-tag>
```
#### 圆角样式
通过`mark`设置为圆角样式
```html
<van-tag mark>标签</van-tag>
<van-tag mark type="danger">标签</van-tag>
<van-tag mark type="primary">标签</van-tag>
<van-tag mark type="success">标签</van-tag>
```
### API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| type | 类型,可选值为`primary` `success` `danger` | `String` | `''`|
| plain | 是否为空心样式 | `Boolean` | `false` |
| mark | 是否为圆角样式 | `Boolean` | `false` |
### Slot
| 名称 | 说明 |
|-----------|-----------|
| default | 自定义 Tag 显示内容 |
+105
View File
@@ -0,0 +1,105 @@
## Toast
### Install
```javascript
import { Toast } from 'vant';
```
### Usage
#### Text
```javascript
Toast('Some messages');
```
#### Loading
```javascript
Toast.loading({
mask: true,
message: 'Loading...'
});
```
#### Success/Fail
```javascript
Toast.success('Success');
Toast.fail('Fail');
```
#### Advanced Usage
```javascript
const toast = Toast.loading({
duration: 0, // continuous display toast
forbidClick: true, // forbid click background
loadingType: 'spinner',
message: '3 seconds'
});
let second = 3;
const timer = setInterval(() => {
second--;
if (second) {
toast.message = `${second} seconds`;
} else {
clearInterval(timer);
Toast.clear();
}
}, 1000);
```
#### $toast Method
After import the Toast component, the $toast method is automatically mounted on Vue.prototype, making it easy to call within a vue component.
```js
export default {
mounted() {
this.$toast('Some messages');
}
}
```
#### Singleton
Toast use singleton mode by default, if you need to pop multiple Toast at the same time, you can refer to the following example
```js
Toast.allowMultiple();
const toast1 = Toast('First Toast');
const toast2 = Toast.success('Second Toast');
toast1.clear();
toast2.clear();
```
### Methods
| Methods | Attribute | Return value | Description |
|-----------|-----------|-----------|-------------|
| Toast | `options | message` | toast instance | Show toast |
| Toast.loading | `options | message` | toast instance | Show loading toast |
| Toast.success | `options | message` | toast instance | Show success toast |
| Toast.fail | `options | message` | toast instance | Show fail toast |
| Toast.clear | `clearAll` | `void` | Close |
| Toast.allowMultiple | - | `void` | Allow multlple toast at the same time |
| Toast.setDefaultOptions | `options` | `void` | Set default options of all toasts |
| Toast.resetDefaultOptions | - | `void` | Reset default options of all toasts |
### Options
| Attribute | Description | Type | Default |
|-----------|-----------|-----------|-------------|
| type | Can be set to `loading` `success` `fail` `html` | `String` | `text` |
| position | Can be set to `top` `middle` `bottom` | `String` | `middle` |
| message | Message | `String` | `''` |
| mask | Whether to show mask | `Boolean` | `false` |
| forbidClick | Whether to forbid click background | `Boolean` | `false` |
| loadingType | Loading icon type, can be set to `spinner` | `String` | `circular` |
| duration | Toast duration(ms), won't disappear if value is 0 | `Number` | `3000` |
+106
View File
@@ -0,0 +1,106 @@
## Toast 轻提示
### 使用指南
```javascript
import { Toast } from 'vant';
```
### 代码演示
#### 文字提示
```javascript
Toast('我是提示文案,建议不超过十五字~');
```
#### 加载提示
```javascript
Toast.loading({
mask: true,
message: '加载中...'
});
```
#### 成功/失败提示
```javascript
Toast.success('成功文案');
Toast.fail('失败文案');
```
#### 高级用法
```javascript
const toast = Toast.loading({
duration: 0, // 持续展示 toast
forbidClick: true, // 禁用背景点击
loadingType: 'spinner',
message: '倒计时 3 秒'
});
let second = 3;
const timer = setInterval(() => {
second--;
if (second) {
toast.message = `倒计时 ${second}`;
} else {
clearInterval(timer);
Toast.clear();
}
}, 1000);
```
#### 组件内调用
引入 Toast 组件后,会自动在 Vue 的 prototype 上挂载 $toast 方法,便于在组件内调用。
```js
export default {
mounted() {
this.$toast('提示文案');
}
}
```
#### 单例模式
Toast 默认采用单例模式,即同一时间只会存在一个 Toast,如果需要在同一时间弹出多个 Toast,可以参考下面的示例
```js
Toast.allowMultiple();
const toast1 = Toast('第一个 Toast');
const toast2 = Toast.success('第二个 Toast');
toast1.clear();
toast2.clear();
```
### 方法
| 方法名 | 参数 | 返回值 | 介绍 |
|-----------|-----------|-----------|-------------|
| Toast | `options | message` | toast 实例 | 展示提示 |
| Toast.loading | `options | message` | toast 实例 | 展示加载提示 |
| Toast.success | `options | message` | toast 实例 | 展示成功提示 |
| Toast.fail | `options | message` | toast 实例 | 展示失败提示 |
| Toast.clear | `clearAll` | `void` | 关闭提示 |
| Toast.allowMultiple | - | `void` | 允许同时存在多个 Toast |
| Toast.setDefaultOptions | `options` | `void` | 修改默认配置,对所有 Toast 生效 |
| Toast.resetDefaultOptions | - | `void` | 重置默认配置,对所有 Toast 生效 |
### Options
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| type | 提示类型,可选值为 `loading` `success` `fail` `html` | `String` | `text` |
| position | 位置,可选值为 `top` `middle` `bottom` | `String` | `middle` |
| message | 内容 | `String` | `''` | - |
| mask | 是否显示背景蒙层 | `Boolean` | `false` |
| forbidClick | 是否禁止背景点击 | `Boolean` | `false` |
| loadingType | 加载图标类型, 可选值为 `spinner` | `String` | `circular` |
| duration | 展示时长(ms),值为 0 时,toast 不会消失 | `Number` | `3000` |

Some files were not shown because too many files have changed in this diff Show More