@@ -262,11 +262,17 @@ export default {
262262
263263 switch (this .type ) {
264264 case ' time' :
265- view = ' hour'
265+ view = this .defaultView && [' hour' , ' minute' ].includes (this .defaultView )
266+ ? this .defaultView
267+ : ' hour'
266268 break
267269 case ' date' :
270+ view = this .defaultView && [' year' , ' month' , ' day' ].includes (this .defaultView )
271+ ? this .defaultView
272+ : ' day'
273+ break
268274 default :
269- view = ' day'
275+ view = this . defaultView || ' day'
270276 break
271277 }
272278
@@ -282,18 +288,8 @@ export default {
282288 this .view = [' date' , ' datetime' ].includes (this .type ) ? ' day' : ' hour'
283289 }
284290 },
285- view (value ) {
286- if (value !== ' year' && value !== ' month' ) {
287- return
288- }
289-
290- let
291- view = this .$refs .selector ,
292- rows = value === ' year' ? this .year - this .yearMin : this .month - this .monthMin
293-
294- this .$nextTick (() => {
295- view .scrollTop = rows * height (view .children [0 ].children [0 ]) - height (view) / 2.5
296- })
291+ view () {
292+ this .__scrollView ()
297293 }
298294 },
299295 computed: {
@@ -441,9 +437,37 @@ export default {
441437 },
442438
443439 /* helpers */
440+ setView (view ) {
441+ if (this .type === ' time' ) {
442+ if ([' hour' , ' minute' ].includes (view)) {
443+ this .view = view
444+ }
445+ }
446+ else if (this .type === ' date' ) {
447+ if ([' year' , ' month' , ' day' ].includes (view)) {
448+ this .view = view
449+ }
450+ }
451+ else {
452+ this .view = view
453+ }
454+ },
444455 __pad (unit , filler ) {
445456 return (unit < 10 ? filler || ' 0' : ' ' ) + unit
446457 },
458+ __scrollView () {
459+ if (this .view !== ' year' && this .view !== ' month' ) {
460+ return
461+ }
462+
463+ let
464+ el = this .$refs .selector ,
465+ rows = this .view === ' year' ? this .year - this .yearMin : this .month - this .monthMin
466+
467+ this .$nextTick (() => {
468+ el .scrollTop = rows * height (el .children [0 ].children [0 ]) - height (el) / 2.5
469+ })
470+ },
447471 __dragStart (ev ) {
448472 stopAndPrevent (ev)
449473
@@ -498,6 +522,9 @@ export default {
498522 __getRepeatEasing (from = 300 , step = 10 , to = 100 ) {
499523 return cnt => cnt ? Math .max (to, from - cnt * cnt * step) : 100
500524 }
525+ },
526+ mounted () {
527+ this .__scrollView ()
501528 }
502529}
503530 </script >
0 commit comments