通过indexOf vue3输出所选日期之间的数据范围

问题描述 投票:0回答:0

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
之间不工作

javascript vue.js datepicker calendar indexof
© www.soinside.com 2019 - 2024. All rights reserved.