Iview的日期选择器在指定的时间范围选择,其余禁止

一个组件传过来的时间值,如2019,在时间选择器中只能选择这一年的时间,其余禁止选择。

1、

<!-- 时间选择器 -->
          <Row class="_time">
            <Col span="12">
            <DatePicker type="daterange"
                        transfer
                        :options="forbidDate"
                        :clearable="false"
                        placement="bottom-end"
                        placeholder="时间选择"
                        style="width: 200px"
                        @on-change="selectDate"
                        v-model="dataVal"></DatePicker>
            </Col>
          </Row>

2、在data中定义传过来的值

let route = this.$route.query.time

3、在data中写:options="forbidDate" 的禁止范围,  用Iview中的disabledDate

 //允许在指定的年份选择
      forbidDate: {
        disabledDate (date) {
          const disabledDay = date.getFullYear();
          return (disabledDay < route || disabledDay > route);
        }
      }

猜你喜欢

转载自www.cnblogs.com/lxs-casually/p/11937266.html
今日推荐