我正在尝试构建一个日历组件,当我单击下一个或上一个时我想要一个过渡,我也想在滑动时添加一个过渡,但是我无法使 vue 过渡工作。我只有一个元素(当前月份),点击下一步或上一个后,它所做的只是更改数据。为了能够添加动态变换:翻译,因为我需要在滑动时获取鼠标位置,我应该创建3个元素(上个月,当前月,下个月)?或者我可以让这项工作只改变数据吗?
我在 vue docs 上尝试了最简单的示例,每次单击按钮时,转换都不起作用。
<transition name="home">
<Calendar></Calendar>
</transition>
.home-enter-active,
.home-leave-active {
transition: opacity 4s;
}
.home-enter,
.home-leave-active {
opacity: 0;
}
这是我的日历组件。
<template>
<div id="calendar" class="calendar">
<div>
<div>{{ state.currentMonthName }}</div>
<div>{{ state.currentYear }}</div>
<div>
<ul class="weekDays">
<li v-for="days in state.weekNames" :key="days">{{ days }}</li>
</ul>
</div>
<div class="days">
<span
@click="
selectDate(state.currentYear, state.currentMonth - 1, state.getLastDayOfPreviousMonth - state.startDay + day);
goPrev();
"
class="lastMonth"
v-for="day in state.startDay"
:key="'empty' + day"
>{{ state.getLastDayOfPreviousMonth - state.startDay + day }}</span
>
<span :class="currenDateClass(state.currentYear, state.currentMonth, day)" @click="selectDate(state.currentYear, state.currentMonth, day)" v-for="day in state.getLastDayOfMonth" :key="day">{{ day }}</span>
<span
@click="
goNext();
selectDate(state.currentYear, state.currentMonth, day);
"
class="lastMonth"
v-for="day in 6 - state.endDay"
:key="'nextMonth' + day"
>{{ day }}</span
>
</div>
</div>
<button @click="goPrev">Prev</button>
<button @click="goNext">Next</button>
</div>
</template>