这次给大家带来如何使用element-ui 限制日期选择,使用element-ui 限制日期选择的注意事项有哪些,下面就是实战案例,一起来看一下。
Element-UI是饿了么前端团队推出的一款基于Vue.js 2.0 的桌面端UI框架,手机端有对应框架是 Mint UI 。
需求场景如下:
指定起止日期,后选的将会受到先选的限制
不同的日期选择器,不过也存在关联关系
实现方法不难,利用了 change 事件,动态改变 picker-options 中的 disableDate 即可。
查看Demo
Template
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <script src= "//unpkg.com/vue/dist/vue.js" ></script>
<script src= "//unpkg.com/element-ui@2.3.8/lib/index.js" ></script>
<p id= "app" >
<template>
<p class = "block" >
<span class = "demonstration" >起始日期</span>
<el- date -picker v-model= "startDate" type= "date" placeholder= "选择日期" :picker-options= "pickerOptionsStart" @change= "changeEnd" >
</el- date -picker>
</p>
<p class = "block" >
<span class = "demonstration" >截止日期</span>
<el- date -picker v-model= "endDate" type= "date" placeholder= "选择日期" :picker-options= "pickerOptionsEnd" @change= "changeStart" >
</el- date -picker>
</p>
</template>
</p>
|
登录后复制
Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | 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
1 2 3 4 | @import url( "//unpkg.com/element-ui@2.3.8/lib/theme-chalk/index.css" );
.block{
margin-top:10px;
}
|
登录后复制
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
怎样使用AngularJS实现标签页tab选项卡切换
如何使用Koa2开发微信二维码扫码支付
以上就是如何使用element-ui 限制日期选择的详细内容,更多请关注php中文网其它相关文章!