ElementUI日期选择器设置可选日期为当月、当月及以后、当月及以前
<el-date-picker
type="date"
v-model="form.date"
:picker-options="pickerOptions">
</el-date-picker>
data(){
return {
pickerOptions: {
disabledDate: (time) => {
const date = new Date()
const year = date.getFullYear()
let month = date.getMonth() + 1
if (month >= 1 && month <= 9) {
month = '0' + month
}
const currentdate = year.toString() + month.toString()
const timeyear = time.getFullYear()
let timemonth = time.getMonth() + 1
if (timemonth >= 1 && timemonth <= 9) {
timemonth = '0' + timemonth
}
const timedate = timeyear.toString() + timemonth.toString()
// 当月
return timedate < currentdate || currentdate < timedate
// 当月及以后
// return timedate < currentdate
// 当月及以前
// return timedate > currentdate
}
}
}
}