mirror of
https://github.com/tenrok/vue2-datepicker.git
synced 2026-06-22 22:10:36 +03:00
feat: add prop formatter to replace the object usage of format
This commit is contained in:
@@ -116,6 +116,7 @@ You can also override some of the default locale by `lang`.
|
||||
| type | select the type of picker | date \|datetime\|year\|month\|time\|week | 'date' |
|
||||
| range | if true, pick the range date | `boolean` | false |
|
||||
| format | to set the date format. similar to moment.js | [token](#token) | 'YYYY-MM-DD' |
|
||||
| formatter | use your own formatter, such as moment.js | [object](#formatter) | - |
|
||||
| value-type | data type of the binding value | [value-type](#value-type) | 'date' |
|
||||
| default-value | default date of the calendar | `Date` | new Date() |
|
||||
| lang | override the default locale | `object` | |
|
||||
@@ -194,12 +195,12 @@ You can also override some of the default locale by `lang`.
|
||||
| Unix Timestamp | X | 1360013296 |
|
||||
| Unix Millisecond Timestamp | x | 1360013296123 |
|
||||
|
||||
#### custom format
|
||||
#### formatter
|
||||
|
||||
The `format` accepts an object to customize formatting.
|
||||
The `formatter` accepts an object to customize formatting.
|
||||
|
||||
```html
|
||||
<date-picker :format="momentFormat" />
|
||||
<date-picker :formatter="momentFormat" />
|
||||
```
|
||||
|
||||
```js
|
||||
@@ -207,13 +208,17 @@ data() {
|
||||
return {
|
||||
// Use moment.js instead of the default
|
||||
momentFormat: {
|
||||
// Date to String
|
||||
//[optional] Date to String
|
||||
stringify: (date) => {
|
||||
return date ? moment(date).format('LL') : ''
|
||||
},
|
||||
// String to Date
|
||||
//[optional] String to Date
|
||||
parse: (value) => {
|
||||
return value ? moment(value, 'LL').toDate() : null
|
||||
},
|
||||
//[optional] getWeekNumber
|
||||
getWeek: (date) => {
|
||||
return // a number
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -309,7 +314,6 @@ If you find this project useful, you can buy me a coffee
|
||||
|
||||

|
||||
|
||||
|
||||
## License
|
||||
|
||||
[MIT](https://github.com/mengxiong10/vue2-datepicker/blob/master/LICENSE)
|
||||
|
||||
Reference in New Issue
Block a user