vue 根据当前月份获取其前六个月的月份

最近六个月显示
在这里插入图片描述
vue调用方法

let month = new Date().getMonth() + 1
this.month = getRecentMonth(month)

js:

/**
 * 根据当前月份获取其前六个月的月份
 * @param month
 * @return {Array|*}
 */
export function getRecentMonth(month) {
	let arr = []
	for(let i = 5;i > 0;i --) {
		let sixMonth = month - i
		if(sixMonth <= 0) {
			sixMonth = 12 + sixMonth
		}
		arr.push(sixMonth + '月')
	}
	arr.push(month + '月')
	return arr;
}

猜你喜欢

转载自blog.csdn.net/ka_xingl/article/details/118902514