elementUI (datepicker) limit the choice of the date on

Specify a start date, after the election before the election will be subject to the restrictions
reference address https://www.jianshu.com/p/c59c8ef6c500
implementation is not difficult to use the change event, dynamically change the picker-options to the disableDate .
In fact, this method is copied from my big brother who over the top. The purpose is to meet next time.
You can quickly solve the problem, as to why such a use. I was not quite sure.
You can ask big brother https://www.jianshu.com/p/c59c8ef6c500

  <div id="app">
        <div class="block">
            <span class="demonstration">起始日期</span>
            <el-date-picker v-model="startDate" type="date" placeholder="选择日期" :picker-options="pickerOptionsStart"
                @change="changeEnd">
            </el-date-picker>
        </div>

        <div class="block">
            <span class="demonstration">截止日期</span>
            <el-date-picker v-model="endDate" type="date" placeholder="选择日期" :picker-options="pickerOptionsEnd"
                @change="changeStart">
            </el-date-picker>
        </div>
    </div>
<script>
    new Vue({
        el: '#app',
        data() {
            return {

                
                pickerOptionsStart: {},
                pickerOptionsEnd: {},
                startDate: '',
                endDate: '',
            };
        },
     
        methods: {
            changeStart() {
                // 赋值
                this.pickerOptionsStart = Object.assign({}, this.pickerOptionsStart, {
                    disabledDate: (time) => {
                        return time.getTime() > this.endDate
                    }
                })
            },

            changeEnd() {
                this.pickerOptionsEnd = Object.assign({}, this.pickerOptionsEnd, {
                    disabledDate: (time) => {
                        return time.getTime() < this.startDate
                    }
                })
            }
        }
    })
</script>

Guess you like

Origin www.cnblogs.com/IwishIcould/p/12594400.html