mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Calendar): initial date incorrect (#8696)
* fix(Calendar): initial date incorrect * feat(Calendar): add getToday function in utils
This commit is contained in:
parent
3f7427b771
commit
e6ca3270ed
@ -24,6 +24,7 @@ import {
|
|||||||
cloneDates,
|
cloneDates,
|
||||||
getPrevDay,
|
getPrevDay,
|
||||||
getNextDay,
|
getNextDay,
|
||||||
|
getToday,
|
||||||
compareDay,
|
compareDay,
|
||||||
calcDateNum,
|
calcDateNum,
|
||||||
compareMonth,
|
compareMonth,
|
||||||
@ -88,13 +89,13 @@ export default defineComponent({
|
|||||||
minDate: {
|
minDate: {
|
||||||
type: Date,
|
type: Date,
|
||||||
validator: isDate,
|
validator: isDate,
|
||||||
default: () => new Date(),
|
default: getToday,
|
||||||
},
|
},
|
||||||
maxDate: {
|
maxDate: {
|
||||||
type: Date,
|
type: Date,
|
||||||
validator: isDate,
|
validator: isDate,
|
||||||
default: () => {
|
default: () => {
|
||||||
const now = new Date();
|
const now = getToday();
|
||||||
return new Date(now.getFullYear(), now.getMonth() + 6, now.getDate());
|
return new Date(now.getFullYear(), now.getMonth() + 6, now.getDate());
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -129,7 +130,7 @@ export default defineComponent({
|
|||||||
return defaultDate;
|
return defaultDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
const now = new Date();
|
const now = getToday();
|
||||||
|
|
||||||
if (type === 'range') {
|
if (type === 'range') {
|
||||||
if (!Array.isArray(defaultDate)) {
|
if (!Array.isArray(defaultDate)) {
|
||||||
|
@ -46,6 +46,11 @@ export function getDayByOffset(date: Date, offset: number) {
|
|||||||
|
|
||||||
export const getPrevDay = (date: Date) => getDayByOffset(date, -1);
|
export const getPrevDay = (date: Date) => getDayByOffset(date, -1);
|
||||||
export const getNextDay = (date: Date) => getDayByOffset(date, 1);
|
export const getNextDay = (date: Date) => getDayByOffset(date, 1);
|
||||||
|
export const getToday = () => {
|
||||||
|
const today = new Date();
|
||||||
|
today.setHours(0, 0, 0, 0);
|
||||||
|
return today;
|
||||||
|
};
|
||||||
|
|
||||||
export function calcDateNum(date: [Date, Date]) {
|
export function calcDateNum(date: [Date, Date]) {
|
||||||
const day1 = date[0].getTime();
|
const day1 = date[0].getTime();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user