2024年12月08日 建站教程
如何利用Lunar
组件获取指定月份的所有老黄历宜忌数据,下面web建站小编给大家简单介绍一下具体获取方法!下面代码中this.year
指的是获取的年份,this.month
指的是获取的月份!
//获取指定月份的天数 getDaysInMonth() { const date = new Date(this.year, this.month, 0); this.daysInMonth = date.getDate(); }, //获取指定月份的每日宜 getDayYiText(){ let cData = [] for(let i=0; i<this.daysInMonth; i++){ const today = this.year + '-' + this.month + '-' + (i+1) const d = Lunar.fromDate(new Date(today)); let l = d.getDayYi(); let arr = [] for (let i=0, j=l.length; i<j; i++){ arr.push(l[i]) } console.log('获取指定月份所有每日宜', arr) } }, //获取指定月份的每日忌 getDayJiText(){ let cData = [] for(let i=0; i<this.daysInMonth; i++){ const today = this.year + '-' + this.month + '-' + (i+1) const d = Lunar.fromDate(new Date(today)); let l = d.getDayJi(); let arr = [] for (let i=0, j=l.length; i<j; i++){ arr.push(l[i]) } console.log('获取指定月份所有每日忌', arr) } }
本文链接:http://so.lmcjl.com/news/19175/