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

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

一、spa

<!-- 时间选择器 -->
          <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>

二、在data中定义传过来的值,根据状况定义的值code

let route = this.$route.query.time

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

 //容许在指定的年份选择
      forbidDate: {
        disabledDate (date) {
      //获取当前的年份 const disabledDay
= date.getFullYear(); return (disabledDay < route || disabledDay > route); } }
相关文章
相关标签/搜索