ElementUI+VUE 在使用ElementUI日期选择器时大于当前月份的日期不可选,默认日期
1,月份选择器,大于当前月份的日期不可选pickerOptions: { //大于当前月分的日期不可选disabledDate: (time) => {var date = new Date();var year = date.getFullYe...
·
1,月份选择器,大于当前月份的日期不可选
pickerOptions: { //大于当前月分的日期不可选
disabledDate: (time) => {
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth() + 1;
if (month >= 1 && month <= 9) {
month = "0" + month;
}
var currentdate = year.toString() + month.toString();
var timeyear = time.getFullYear();
var timemonth = time.getMonth() + 1;
if (timemonth >= 1 && timemonth <= 9) {
timemonth = "0" + timemonth;
}
var timedate = timeyear.toString() + timemonth.toString();
return currentdate < timedate;
}
},
2,日期选择器,小于当前日期不可选
pickerOptions: {
disabledDate(time) {
return time.getTime() < Date.now();
}
},
3,月份选择器,时间段选择,添加开始月份默认为当月的钱前三个月(例如2019-02),结束月份为当前月份(例如2019-05)
//默认月份
defaultDate(){
let _this = this;
//获取新的时间(2019.4.12)
let date = new Date()
//获取当前时间的年份转为字符串
let endYear = date.getFullYear().toString() //'2019'
let staYear = endYear
//获取月份,由于月份从0开始,此处要加1,判断是否小于10,如果是在字符串前面拼接'0'
let staMonth = 0
let endMonth = date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1).toString():(date.getMonth()+1).toString() //'04'
if(date.getMonth()+1 == 1){
staYear = (date.getFullYear()-1).toString()
staMonth = (12).toString()
}else {
staMonth = date.getMonth() < 10 ? '0'+(date.getMonth()).toString():(date.getMonth()).toString() //'04'
}
//字符串拼接,开始时间,结束时间
let end = endYear + endMonth //当月2019-04
let beg = staYear + staMonth //当月减3 2019-01
_this.formInline.startMonth=beg
_this.formInline.endMonth=end //将值设置给插件绑定的数据
},
更多推荐
已为社区贡献1条内容
所有评论(0)