el-datepicker限制只能选时间跨度1年的。

 <!-- 时间选择器 -->
                <el-form-item label="创建时间" :key="clearIndex" class="timeInfo">
                    <td-date-time v-model="datas" :pickerOptions="pickerOptions" :editable='false' type="daterange" valueFormat="yyyy-MM-dd" @change="clearTime" :separator="$t('accountability.TO')"
                    :start-placeholder="$t('licenseCommon.START_TIME')" :end-placeholder="$t('licenseCommon.END_TIME')"></td-date-time>
                </el-form-item>


            // 时间跨度为之前一年
            pickerOptions: {
                disabledDate: () => false,
                onPick: ({ maxDate, minDate }) => {
                  if (minDate && !maxDate) {
                    const oneYear = 365 * 24 * 60 * 60 * 1000;
                    this.pickerOptions.disabledDate = time => {
                      return time.getTime() < minDate.getTime() || time.getTime() > minDate.getTime() + oneYear;
                    };
                  } else {
                    this.pickerOptions.disabledDate = () => false;
                  }
                },
            },

我自己封装过一遍了,重点看pikerOptions。

你可能感兴趣的:(前端,javascript,算法)