1.安装依赖
npm install --save chinese-lunar-calendar
2.在vue文件中的使用
<script>
import { getLunar } from 'chinese-lunar-calendar'
export default {
data() {
return {
getLunarDay: '',
year: new Date().getFullYear(),
month: new Date().getMonth() + 1,
date: new Date().getDate()
}
},
mounted() {
// 获取农历
this.getLunarDay = getLunar(this.year, this.month, this.date)
console.log(this.getLunarDay)
}
}
</script>
3.取值
<p>农历:{{getLunarDay.dateStr}}</p>
输出:
需要哪个值就取哪个值哦O(∩_∩)O
dateStr: “二月廿五” //农历中文
isLeap: false //是否闰月
lunarDate: 25 //农历日期
lunarMonth: 2 //农历月份
lunarYear: “辛丑年” //农历年份,年以正月初一开始
solarTerm: null //节气,null代表没有
zodiac: “牛” //生肖,生肖以正月初一开始