1、在props中新增dateList属性(通过父组件接口获取可选日期)
dateList: {
type: Array,
default: false
},
2、修改openDisAbled函数
openDisAbled: function(year, month, day) {
let bool = true;
let date = `${year}/${month}/${day}`;
// let today = this.today.replace(/\-/g, '/');
let min = `${this.min.year}/${this.min.month}/${this.min.day}`;
let max = `${this.max.year}/${this.max.month}/${this.max.day}`;
let timestamp = new Date(date).getTime();
// 获取父组件传来的日期数组
let list=this.dateList
// 循环更改数据进行判断
list.map(item=>{
let date= this.initDate(item);
let dateT= `${date.year}/${date.month}/${date.day}`;
if (timestamp == new Date(dateT).getTime()) {
bool = false;
}
})
// 注释原来的根据最大最小日期判断的代码
// if (timestamp >= new Date(min).getTime() && timestamp <= new Date(max).getTime()) {
// bool = false;
// }
return bool;
},
4、最后在父组件添加:dateList='dateList'