@@ -168,7 +168,7 @@ export default {
168
168
default: ' date' ,
169
169
},
170
170
format: {
171
- type: [ String , Object ] ,
171
+ type: String ,
172
172
default () {
173
173
const map = {
174
174
date: ' YYYY-MM-DD' ,
@@ -181,6 +181,9 @@ export default {
181
181
return map[this .type ] || map .date ;
182
182
},
183
183
},
184
+ formatter: {
185
+ type: Object ,
186
+ },
184
187
range: {
185
188
type: Boolean ,
186
189
default: false ,
@@ -347,29 +350,42 @@ export default {
347
350
},
348
351
},
349
352
},
353
+ created () {
354
+ if (typeof this .format === ' object' ) {
355
+ console .warn (
356
+ " [vue2-datepicker]: The prop `format` don't support Object any more. You can use the new prop `formatter` to replace it"
357
+ );
358
+ }
359
+ },
350
360
methods: {
351
361
handleClickOutSide (evt ) {
352
362
const { target } = evt;
353
363
if (! this .$el .contains (target)) {
354
364
this .closePopup ();
355
365
}
356
366
},
367
+ getFormatter (key ) {
368
+ return (
369
+ (isObject (this .formatter ) && this .formatter [key]) ||
370
+ (isObject (this .format ) && this .format [key])
371
+ );
372
+ },
357
373
getWeek (date , options ) {
358
- if (isObject ( this . format ) && typeof this .format . getWeek === ' function' ) {
359
- return this .format . getWeek (date, options);
374
+ if (typeof this .getFormatter ( ' getWeek' ) === ' function' ) {
375
+ return this .getFormatter ( ' getWeek' ) (date, options);
360
376
}
361
377
return getWeek (date, options);
362
378
},
363
379
parseDate (value , fmt ) {
364
- if (isObject ( this . format ) && typeof this .format . parse === ' function' ) {
365
- return this .format . parse (value, fmt);
380
+ if (typeof this .getFormatter ( ' parse' ) === ' function' ) {
381
+ return this .getFormatter ( ' parse' ) (value, fmt);
366
382
}
367
383
const backupDate = new Date ();
368
384
return parse (value, fmt, { locale: this .locale .formatLocale , backupDate });
369
385
},
370
386
formatDate (date , fmt ) {
371
- if (isObject ( this . format ) && typeof this .format . stringify === ' function' ) {
372
- return this .format . stringify (date, fmt);
387
+ if (typeof this .getFormatter ( ' stringify' ) === ' function' ) {
388
+ return this .getFormatter ( ' stringify' ) (date, fmt);
373
389
}
374
390
return format (date, fmt, { locale: this .locale .formatLocale });
375
391
},
0 commit comments