VueJS Datepicker:根据月份动态更改数据

时间:2019-01-02 19:44:20

标签: vue.js datepicker

我是VueJS的新手,我正在将vue-hotel-datepicker库合并到我的项目中。

目标:根据月份更改minNights数据属性。如documentation中所述,我能够简单地覆盖该值。

enter image description here

问题minNights应该在8月和7月为8。当我使用Vue检查器时,可以看到HotelDatePicker组件(从库中导入)具有'activeMonthIndex',因此我相信我应该使用它。但是,如何从父母那里访问此数据属性?如何根据月份动态更改minNights属性?

enter image description here

我的模板:

<datepicker
    :startDate="startDate"
    @check-in-changed="setCheckInDate"
    @check-out-changed="setCheckOutDate"
    :maxNights="21"
    :minNights="minNights" //dynamic based on month
    :checkIn="checkIn"
    :checkOut="checkOut"
    :disabledDates="bookedDates"
    :firstDayOfWeek="1"
    :i18n="lang"
    :showYear="true"
 >

我为希望查看我的代码的人制作了gist。 任何指导都将不胜感激。

1 个答案:

答案 0 :(得分:1)

您的minNights道具应绑定到computed属性,例如:

<datepicker
:startDate="startDate"
@check-in-changed="setCheckInDate"
@check-out-changed="setCheckOutDate"
:maxNights="21"
:minNights="minNights" //dynamic based on month
:checkIn="checkIn"
:checkOut="checkOut"
:disabledDates="bookedDates"
:firstDayOfWeek="1"
:i18n="lang"
:showYear="true"
>

脚本:

  computed:{
        minNights(){

          let currentMonth=this.$children[0]._data.activeMonthIndex;
          if(currentMonth==6 || currentMonth==7){
             return currentMonth;
           }   
         }
     }