const year = 2014;
const month = 09;
// months start at index 0 in momentjs, so we subtract 1
const startDate = moment([year, month - 1, 01]).format("YYYY-MM-DD");
// get the number of days for this month
const daysInMonth = moment(startDate).daysInMonth();
// we are adding the days in this month to the start date (minus the first day)
const endDate = moment(startDate).add(daysInMonth - 1, 'days').format("YYYY-MM-DD");
console.log(`start date: ${startDate}`);
console.log(`end date: ${endDate}`);
<script
src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment.min.js">
</script>
Потому что этот метод рендеринга - static
. По определению методы static
не могут получить доступ к переменной экземпляра. Вы должны удалить этот модификатор, если это возможно, и он должен работать.