Element-UI是餓了么前端團(tuán)隊推出的一款基于Vue.js 2.0 的桌面端UI框架,手機(jī)端有對應(yīng)框架是 Mint UI 。
需求場景如下:
實(shí)現(xiàn)方法不難,利用了 change 事件,動態(tài)改變 picker-options 中的 disableDate 即可。
查看Demo
Template
<script src="https://www.gxlcms.com//unpkg.com/vue/dist/vue.js"></script> <script src="https://www.gxlcms.com//unpkg.com/element-ui@2.3.8/lib/index.js"></script> <div id="app"> <template> <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> </template> </div>
Script
var Main = { 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 } }) } } }; var Ctor = Vue.extend(Main) new Ctor().$mount('#app')
Style
@import url("http://unpkg.com/element-ui@2.3.8/lib/theme-chalk/index.css"); .block{ margin-top:10px; }
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com