docs(Form): add Area demo

This commit is contained in:
陈嘉涵 2020-02-11 15:24:09 +08:00
parent ed16eb7a59
commit fb3892e302
6 changed files with 159 additions and 5 deletions

View File

@ -244,9 +244,9 @@ export default {
<van-field
readonly
clickable
name="picker"
name="datetimePicker"
:value="value"
label="DatetimePicker"
label="Datetime Picker"
placeholder="Select time"
@click="showPicker = true"
/>
@ -284,6 +284,48 @@ export default {
};
```
### Field Type - Area
```html
<van-field
readonly
clickable
name="area"
:value="value"
label="Area Picker"
placeholder="Select area"
@click="showArea = true"
/>
<van-popup v-model="showArea" position="bottom">
<van-area
:area-list="areaList"
@confirm="onConfirm"
@cancel="onCancel"
/>
</van-popup>
```
```js
export default {
data() {
return {
value: '',
showArea: false,
areaList: {}
};
},
methods: {
onConfirm(values) {
this.value = values.map(item => item.name).join('/');
this.showArea = false;
},
onCancel() {
this.showArea = false;
},
},
};
```
## API
### Props

View File

@ -250,7 +250,7 @@ export default {
<van-field
readonly
clickable
name="picker"
name="datetimePicker"
:value="value"
label="时间选择"
placeholder="点击选择时间"
@ -290,6 +290,48 @@ export default {
};
```
### 表单项类型 - 省市区选择器
```html
<van-field
readonly
clickable
name="area"
:value="value"
label="地区选择"
placeholder="点击选择省市区"
@click="showArea = true"
/>
<van-popup v-model="showArea" position="bottom">
<van-area
:area-list="areaList"
@confirm="onConfirm"
@cancel="onCancel"
/>
</van-popup>
```
```js
export default {
data() {
return {
value: '',
showArea: false,
areaList: {} // 数据格式见 Area 组件文档
};
},
methods: {
onConfirm(values) {
this.value = values.map(item => item.name).join('/');
this.showArea = false;
},
onCancel() {
this.showArea = false;
},
},
};
```
## API
### Props

View File

@ -49,6 +49,7 @@
<field-type-picker />
<field-type-datetime-picker />
<field-type-area />
<div style="margin: 16px 16px 0;">
<van-button type="info" round block>{{ $t('submit') }}</van-button>
@ -58,6 +59,7 @@
</template>
<script>
import FieldTypeArea from './FieldTypeArea';
import FieldTypePicker from './FieldTypePicker';
import FieldTypeDatetimePicker from './FieldTypeDatetimePicker';
@ -94,6 +96,7 @@ export default {
},
components: {
FieldTypeArea,
FieldTypePicker,
FieldTypeDatetimePicker,
},

View File

@ -0,0 +1,58 @@
<template>
<div>
<van-field
readonly
clickable
name="area"
:value="value"
:label="$t('picker')"
:placeholder="$t('placeholder')"
@click="showArea = true"
/>
<van-popup v-model="showArea" position="bottom">
<van-area
:area-list="$t('areaList')"
@confirm="onConfirm"
@cancel="onCancel"
/>
</van-popup>
</div>
</template>
<script>
import AreaList from '../../area/demo/area';
import AreaListEn from '../../area/demo/area-en';
export default {
i18n: {
'zh-CN': {
picker: '地区选择',
areaList: AreaList,
placeholder: '点击选择省市区',
},
'en-US': {
picker: 'Area Picker',
areaList: AreaListEn,
placeholder: 'Select area',
},
},
data() {
return {
value: '',
showArea: false,
};
},
methods: {
onConfirm(values) {
this.value = values.map(item => item.name).join('/');
this.showArea = false;
},
onCancel() {
this.showArea = false;
},
},
};
</script>

View File

@ -3,7 +3,7 @@
<van-field
readonly
clickable
name="picker"
name="datetimePicker"
:value="value"
:label="$t('label')"
:placeholder="$t('placeholder')"

View File

@ -170,7 +170,16 @@ exports[`renders demo correctly 1`] = `
<div role="button" tabindex="0" class="van-cell van-cell--clickable van-field">
<div class="van-cell__title van-field__label"><span>时间选择</span></div>
<div class="van-cell__value van-field__value">
<div class="van-field__body"><input type="text" name="picker" readonly="readonly" placeholder="点击选择时间" class="van-field__control"></div>
<div class="van-field__body"><input type="text" name="datetimePicker" readonly="readonly" placeholder="点击选择时间" class="van-field__control"></div>
</div>
</div>
<!---->
</div>
<div>
<div role="button" tabindex="0" class="van-cell van-cell--clickable van-field">
<div class="van-cell__title van-field__label"><span>地区选择</span></div>
<div class="van-cell__value van-field__value">
<div class="van-field__body"><input type="text" name="area" readonly="readonly" placeholder="点击选择省市区" class="van-field__control"></div>
</div>
</div>
<!---->