i在选择两个日期时,在VUE3上做一个datepicker,我需要所选日期之间的日子要悬停。我使用“indexOf”方法
:class="{
active: currentMonthInNumber + '/' + date + '/' + currentYear === firstDay || currentMonthInNumber + '/' + date + '/' + currentYear === lastDay,
between: between.includes(date),
}"
@click="choosingDates(date)"
<script>
data() {
return {
firstDay: false,
lastDay: false,
between: [],
methods: {
choosingDates(date) {
date = new Date(this.currentYear, this.currentMonthInNumber - 1, date);
const dateFormatter = Intl.DateTimeFormat('en-US');
let newDate = dateFormatter.format(date)
if (this.firstDay === false) {
this.firstDay = newDate;
} else if (this.lastDay === false) {
this.lastDay = newDate;
this.setBetween();
}
},
setBetween() {
const start = new Date(this.firstDay);
const end = new Date(this.lastDay);
let date = new Date(start);
while (date <= end) {
console.log(date);
let newDate = date.setDate(date.getDate() + 1);
date = new Date(newDate);
this.between.push(date);
}
},
在
console.log(date);
中显示firstDay
和lastDay
之间的所有日子,但在:class
之间不工作