[new feature] DatetimePicker: add filter prop

This commit is contained in:
陈嘉涵
2019-05-23 17:06:56 +08:00
parent 14ac581ac6
commit ab441cca9e
6 changed files with 167 additions and 18 deletions
+39 -5
View File
@@ -60,7 +60,8 @@ export default {
```
### 选择日期(年月)
通过传入 `formatter` 函数对选项文字进行处理
通过传入`formatter`函数,可以对选项文字进行格式化处理
```html
<van-datetime-picker
@@ -96,10 +97,10 @@ export default {
```html
<van-datetime-picker
v-model="currentDate"
v-model="currentTime"
type="time"
:min-hour="minHour"
:max-hour="maxHour"
:min-hour="10"
:max-hour="20"
/>
```
@@ -107,12 +108,44 @@ export default {
export default {
data() {
return {
currentDate: '12:00'
currentTime: '12:00'
};
}
}
```
### 选项过滤器
通过传入`filter`函数,可以对选项数组进行过滤,实现自定义时间间隔
```html
<van-datetime-picker
v-model="currentTime"
type="time"
:filter="filter"
/>
```
```js
export default {
data() {
return {
currentTime: '12:00'
};
},
methods: {
filter(type, options) {
if (type === 'minute') {
return options.filter(option => option % 5 === 0)
}
return options;
}
}
}
```
## API
### Props
@@ -126,6 +159,7 @@ export default {
| max-hour | 可选的最大小时,针对 time 类型 | `Number` | `23` | - |
| min-minute | 可选的最小分钟,针对 time 类型 | `Number` | `0` | 1.1.15 |
| max-minute | 可选的最大分钟,针对 time 类型 | `Number` | `59` | 1.1.15 |
| filter | 选项过滤函数 | `(type, values) => values` | - | 2.0.0 |
| formatter | 选项格式化函数 | `(type, value) => value` | - | 1.1.14 |
| title | 顶部栏标题 | `String` | `''` | 1.0.4 |
| show-toolbar | 是否显示顶部栏 | `Boolean` | `false` | 1.0.2 |