javascript - VueJS 日期选择器 : dynamically change data based on month

标签 javascript vue.js vuejs2 datepicker vue-component

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

目标:根据月份更改minNights 数据属性。我能够按照 documentation 中的描述简单地覆盖该值.

enter image description here

问题:minNights 在八月和七月应该是 8。当我使用 Vue 检查器时,我可以看到 HotelDatePicker 组件(从库中导入)有一个“activeMonthIndex”,所以我相信我应该使用它。但是我怎样才能从我的 parent 那里访问这个数据属性呢?如何根据月份动态更改 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对于那些希望看到我的代码的人。 非常感谢任何指导。

最佳答案

您的 minNights Prop 应该绑定(bind)到一个 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;
           }   
         }
     }

关于javascript - VueJS 日期选择器 : dynamically change data based on month,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54012252/

相关文章:

javascript onclick()事件不适用于div容器内文本的chrome

javascript - 如何设置react组件的iframe内容

javascript - 如何在 Vuejs 2 中声明全局方法/对象?

javascript - 类型错误 : Cannot read property '_modulesNamespaceMap' of undefined in Vue

javascript - 尝试 catch ex.stack 只获取第一行

javascript - 如何正确地链接 Vuex 操作,并正确地改变调用之间的状态?

vue.js - Nuxt 客户端呈现的 DOM 与服务器呈现的内容不匹配

javascript - VueJS 在 v-model 中反转值

php - SQLSTATE[23000] : Integrity constraint violation: 1048. 将数据从 vue 发布到 laravel Controller

javascript - Bootstrap 表单重复内容