hasyrails / calendar-vue-original

0 stars 0 forks source link

34 date font color condition / 日付の色表示の条件を変更 #71

Closed hasyrails closed 4 years ago

hasyrails commented 4 years ago

正しく条件分岐できていない Image from Gyazo

hasyrails commented 4 years ago
hasyrails commented 4 years ago

背景色を条件分岐させようと

<div
  class="calendar-date"
  v-for="(day, index) in week"
  :key="index"
>
  <draggable  v-model="devidedSchedule" group="cards" @start="drag=true" @end="drag=false" :options="options">
    <Schedule 
          :devidedSchedule="devidedSchedule"
          v-for="devidedSchedule in devidedSchedules"
          v-if="devidedSchedule.date==day.date&&devidedSchedule.month==day.month&&devidedSchedule.year==day.year"
          style="flex:1;min-height:1px;min-width:1px;max-height:100px;max-width:150px;text-align: center;margin-bottom:10px;"
>
    </Schedule>
  </draggable>
</div>

の部分をv-ifで条件分岐させようとすると カレンダー表示の配列がバグる?

hasyrails commented 4 years ago

方針変更

色を変更するのは日付文字の色とする

<div v-if="day.month===currentMonth" style="font-weight:200;">{{day.date}}</div>
<div v-if="day.month!==currentMonth" style="color:#D3D3D3;">{{ day.date }}</div>
hasyrails commented 4 years ago

メソッドの変更

currentMonthが0になることに対し、 day.monthは正しい連動をすることで不整合が生じるのを prevMonth()メソッド / nextMonth()メソッドを変更することで解消

nextMonth() {
      this.currentDate = moment(this.currentDate).add(1, "month").format('YYYY/MM');
      if(this.currentMonth <11){
        this.currentMonth++;
      }else if(this.currentMonth===11){
        this.currentMonth = 12
      }else{
        this.currentMonthReset()
      }
    },
currentMonthReset(){
      this.currentMonth = 1
},
prevMonth() {
      this.currentDate = moment(this.currentDate).subtract(1, "month").format('YYYY/MM');

      if(this.currentMonth <=12 && this.currentMonth > 1){
        this.currentMonth--;
      }else if(this.currentMonth===1){
        this.currentMonth = 12
      }
      this.getCalendar();
},