uniapp的uView的Calender禁用某些日期,并给出一些提示
作者:互联网
u-calendar__content__item__inner
1.在这个class中添加自己想要的格式
<view class="leased" v-if="item.isUse">
已租赁
</view>
2,在changeData方法中更改数据格式,然后匹配自己的禁用日期时间
this.daysArr.forEach((item,index)=>{
this.daysArr[index] = {
isUse:false,
data:item
}
let month = this.month<10?('0'+this.month):this.month
let day = item<10?('0'+item):item
let date = `${this.year}-${month}-${day}`
if(this.disabledTime.includes(date)){
this.daysArr[index].isUse=true
}
})
3.在openDisabled中修改原来判断
for(var i = 0;i<this.disabledTime.length;i++){
// console.log(this.disabledTime[i])
let newDay = this.disabledTime[i].replace(/\-/g,'/')
newDay = new Date(newDay).getTime()
if(timestamp===newDay){
bool=true;
}
}
newDay为传入禁用日期数组
4.下方为获取开始结束日期之内的所有日期
getAllDate(start, end) {
let dateArr = []
start = start.split(' ')
let startArr = start[0].split('-')
end = end.split(' ')
let endArr = end[0].split('-')
let db = new Date()
db.setUTCFullYear(startArr[0], startArr[1] - 1, startArr[2])
let de = new Date()
de.setUTCFullYear(endArr[0], endArr[1] - 1, endArr[2])
let unixDb = db.getTime()
let unixDe = de.getTime()
let stamp
const oneDay = 24 * 60 * 60 * 1000;
for (stamp = unixDb; stamp <= unixDe;) {
dateArr.push(this.format(new Date(parseInt(stamp))))
stamp = stamp + oneDay
}
return dateArr
},
标签:uniapp,end,uView,start,let,split,Calender,endArr,startArr 来源: https://blog.csdn.net/qq_20497071/article/details/112969582