Update timerangeselect dynamically

This commit is contained in:
Matthias 2021-07-04 16:25:41 +02:00
parent 8c8c430513
commit 466f809425

View File

@ -37,7 +37,7 @@
</template>
<script lang="ts">
import { Component, Vue, Emit, Prop } from 'vue-property-decorator';
import { Component, Vue, Emit, Prop, Watch } from 'vue-property-decorator';
import { dateFromString, dateStringToTimeRange, timestampToDateString } from '@/shared/formatters';
const now = new Date();
@ -54,10 +54,12 @@ export default class TimeRangeSelect extends Vue {
return this.timeRange;
}
created() {
if (!this.value) {
this.dateFrom = timestampToDateString(new Date(now.getFullYear(), now.getMonth() - 1, 1));
} else {
@Watch('value')
valueChanged() {
this.updateInput();
}
updateInput() {
const tr = this.value.split('-');
if (tr[0]) {
this.dateFrom = timestampToDateString(dateFromString(tr[0], 'yyyyMMdd'));
@ -66,6 +68,13 @@ export default class TimeRangeSelect extends Vue {
this.dateTo = timestampToDateString(dateFromString(tr[1], 'yyyyMMdd'));
}
}
created() {
if (!this.value) {
this.dateFrom = timestampToDateString(new Date(now.getFullYear(), now.getMonth() - 1, 1));
} else {
this.updateInput();
}
this.emitTimeRange();
}