ManukMinasyan / vue-functional-calendar

Vue.js Functional Calendar | Component/Package
https://vue-functional-calendar.now.sh/
MIT License
468 stars 84 forks source link

Setting initial date #74

Closed engineertdog closed 4 years ago

engineertdog commented 4 years ago

When trying to set the initial date, the following code works (the date and time are selected properly), but throws an error.

While I'm using date.value.format("HH") for the hour value, I should be able to use date.value.hour(). However, when I use the hour function, the current hour is not selected.

const date = computed(() => moment());
const dateData = ref({
      selectedDate: date.value.format("MM/DD/YYYY"),
      selectedDateTime: date.value.format("MM/DD/YYYY HH:mm"),
      selectedHour: date.value.format("HH"),
      selectedMinute: date.value.minute(),
      dateRange: {
        end: {
          date: false,
          dateTime: false,
          hour: "00",
          minute: "00"
        },
        start: {
          date: false,
          dateTime: false,
          hour: "00",
          minute: "00"
        }
      }
    });

The error:

[Vue warn]: Error in v-on handler: "TypeError: Cannot read property 'find' of undefined"
TypeError: Cannot read property 'find' of undefined
[Vue warn]: Error in created hook: "TypeError: Cannot read property 'length' of undefined"

The error corresponds to the following code block:

created() {
            let selectedDates = this.$parent.calendar.selectedDates;
            this.currentSelectedDate = selectedDates[selectedDates.length - 1]; // here
}