一个组件传过来的时间值,如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); } }