我使用lunar-calendar来获取当前的农历,但是显示失败,请各位帮我修改代码,使其可以正常显示对应的农历日期,下面是对应的过程,我想在对应的格子里面显示当前的日而不显示年月,然后再下面在显示对应的农历日期
下面是我获取公历日期的代码,
<template>
<div class="lunar-calendar">
<el-calendar v-model="currentDate">
<template #date-cell="{ data }">
<div>
{{ data.day }}
</div>
</template>
</el-calendar>
</div>
</template>
<script setup>
import { ref } from 'vue';
const currentDate = ref(new Date());
</script>
<style scoped>
.lunar-calendar {
margin: 20px;
}
</style>
下面是显示的图片

然后我在公历下面添加了农历显示,但是其只显示12月16一个日子,下面是对应的代码
<template>
<div class="lunar-calendar">
<el-calendar v-model="currentDate">
<template #date-cell="{ data }">
<div>
<!-- 只显示日期,不显示年份和月份 -->
{{ data.day }}
<!-- 显示农历日期 -->
<div class="lunar-date" v-if="lunarDate">
{{ lunarDate.month }}月{{ lunarDate.day }}
</div>
</div>
</template>
</el-calendar>
</div>
</template>
<script setup>
import {ref, computed} from 'vue';
import chineseLunar from 'chinese-lunar';
const currentDate = ref(new Date());
const lunarDate = computed(() => {
const solarDate = new Date(currentDate.value.getFullYear(), currentDate.value.getMonth(), currentDate.value.getDate());
const lunar = chineseLunar.solarToLunar(solarDate);
return {
month: lunar.month + 1, // 农历月份是从0开始的,所以需要加1
day: lunar.day
};
});
</script>
<style scoped>
.lunar-calendar {
margin: 20px;
}
.lunar-date {
font-size: 12px;
}
</style>现在所有的农历都显示为12月16了
下面是对应的截图
