如何使今天的日期(v-present)始终位于 vuetify 日历的中间列
how to make today date (v-present) always the middle column in vuetify calendar
vuetify v-calendar 在 Type week 中有特定的天数顺序(星期日到星期六),然后根据今天的日期从左到右移动 class v-present,如何使今天的日期有 (v-目前)在中间栏 enter image description here
经过长时间的反复搜索和阅读文档后,我找到了一个解决方案,v-calendar 使用一个名为 weekdays 的道具,它是一个数组,其中一周从 sun (0) 开始,在 sat (6) 结束) 这是该道具的默认形式 [0,1,2,3,4,5,6]
所以我在数据 属性 中创建了 weekDays 然后 运行 这个方法在 mounted hook 中有效
getWeekDays() {
const dayNames = ["Sun", "Mon", "Tues", "Wed", "Thu", "Fri", "Sat"];
let dateObj = new Date();
let dayName = dayNames[dateObj.getDay()];
switch(dayName){
case"Sun":
this.weekDays = [4,5,6,0,1,2,3]
break;
case"Mon":
this.weekDays = [5,6,0,1,2,3,4]
break;
case"Tues":
this.weekDays = [6,0,1,2,3,4,5]
break;
case"Wed":
this.weekDays = [0,1,2,3,4,5,6]
break;
case"Thu":
this.weekDays = [1,2,3,4,5,6,0]
break;
case"Fri":
this.weekDays = [2,3,4,5,6,0,1]
break;
case"Sat":
this.weekDays = [3,4,5,6,0,1,2]
break;
default:
this.weekDays = [0,1,2,3,4,5,6]
}
},
vuetify v-calendar 在 Type week 中有特定的天数顺序(星期日到星期六),然后根据今天的日期从左到右移动 class v-present,如何使今天的日期有 (v-目前)在中间栏 enter image description here
经过长时间的反复搜索和阅读文档后,我找到了一个解决方案,v-calendar 使用一个名为 weekdays 的道具,它是一个数组,其中一周从 sun (0) 开始,在 sat (6) 结束) 这是该道具的默认形式 [0,1,2,3,4,5,6]
所以我在数据 属性 中创建了 weekDays 然后 运行 这个方法在 mounted hook 中有效
getWeekDays() {
const dayNames = ["Sun", "Mon", "Tues", "Wed", "Thu", "Fri", "Sat"];
let dateObj = new Date();
let dayName = dayNames[dateObj.getDay()];
switch(dayName){
case"Sun":
this.weekDays = [4,5,6,0,1,2,3]
break;
case"Mon":
this.weekDays = [5,6,0,1,2,3,4]
break;
case"Tues":
this.weekDays = [6,0,1,2,3,4,5]
break;
case"Wed":
this.weekDays = [0,1,2,3,4,5,6]
break;
case"Thu":
this.weekDays = [1,2,3,4,5,6,0]
break;
case"Fri":
this.weekDays = [2,3,4,5,6,0,1]
break;
case"Sat":
this.weekDays = [3,4,5,6,0,1,2]
break;
default:
this.weekDays = [0,1,2,3,4,5,6]
}
},