【发布时间】:2022-01-25 10:32:01
【问题描述】:
我正在尝试创建一个看起来像图像的日历,但我无法做到。有没有更好的方法来做到这一点?
这是我的代码(我正在使用时刻来执行此操作)。
import React from 'react'
import moment from 'moment'
const Calender = () => {
const value = moment()
const startMonth = value.clone().startOf('year')
const endMonth = value.clone().endOf('year')
const month = startMonth.clone()
const calendar = [];
// while(startMonth.isBefore(endMonth, 'month')) {
// calendar.push(
// Array(7).fill(0).map(()=>month.add(1,'month').clone())
// )
// }
console.log('month ' + month.format('MMM'));
while (month.format('MMM') === 'Dec') {
calendar.push(
// Array(12).map(()=>month.add(1,'month').clone())
console.log(month.add(1,'month'))
)
}
return ( <>
{console.log(calendar)}
<div>
{calendar}
{endMonth.format('MMM')}
</div>
</> );
}
export default Calender;
【问题讨论】: