weekOfMonth()
calculates the current month and week within that month.
<template>
<h3>{{ weekOfMonth }}</h3>
</template>
<script lang="ts">
export default class HomeView extends Vue {
const moment = require("moment");
private get weekOfMonth(): string {
const nowDate = moment().utc(true);
let week: number = nowDate.week() - moment(nowDate).startOf("month").week() + 1;
return `This Month: ${nowDate.month() + 1} / This Week: ${week}`;
}
}
</script>
result: This Month: 7 / This Week: 4
result when 'get' is not used: function () { [native code] }
Why is a getter needed to retrieve the return value?