Как вызывать функции при экспорте из компонента vue plugin - PullRequest
0 голосов
/ 08 октября 2019

Итак, я использую компонент VCalendar, и у меня есть функция updateStats (), которую я хочу вызывать при обновлении VCalendar. Пока у меня есть:


<script src='https://unpkg.com/v-calendar@next'></script>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import { DateTime, Duration } from 'luxon';

import { printTime, getScheduleFromDay, getPeriod, getFullSchedule, allGrades,
plusDays } from '@/schedule';
import { Day, Schedule, Period, getPeriodName, getScheduleName } from '@/schedule/enums';
import { RegularSchedule, BlockEvenSchedule, BlockOddSchedule } from '@/schedule/schedules';

import VCalendar from 'v-calendar';

Vue.use(VCalendar, {
  componentPrefix: 'vc',
  data: {
    date: new Date()
  },
  watch: {
    date: function() {
      this.updateStats()
    }
  }
});

@Component({})
export default class Home extends Vue {

  private minutes: number = 0
  private schedule: Schedule = Schedule.NONE;
  private grade = allGrades[2];
  private currentPeriod = { start: 0, end: 1440, period: Period.NONE };
  private date = new Date();
  public daysShifted = 0;
  public arrowsUsed = true;

  updateStats() {
    const currentDate = DateTime.local().setZone("America/Los_Angeles").plus(Duration.fromMillis(this.daysShifted * 86400000));
    this.minutes = currentDate.minute + (currentDate.hour * 60)

    this.grade = this.$store.state.settings.grade;
    this.schedule = getScheduleFromDay(currentDate.month, currentDate.day, currentDate.year, currentDate.weekday, this.grade);
    this.currentPeriod = getPeriod(this.minutes, this.schedule, this.grade);
    if (this.arrowsUsed) {
      this.date = new Date(new Date().valueOf() + this.daysShifted*86400000)
    }
    this.arrowsUsed = false;
    this.daysShifted = Math.ceil((this.date.valueOf() - new Date().valueOf())/86400000)
  }

Проблема в том, что я не могу вызвать updateStats () или this.updateStats () из плагина, потому что> свойство 'updateStats' не существует для типа '{date:() => void;}

...