<el-calendar v-model="value" id="calendar">
<!-- 这里使用的是 2.5 slot 语法,对于新项目请使用 2.6 slot 语法-->
<template slot="dateCell" slot-scope="{date, data}">
<!--date 单元格代表的日期
data{ type, isSelected, day},type 表示该日期的所属月份,可选值有 prev-month,current-month,next-month;isSelected 标明该日期是否被选中;day 是格式化的日期,格式为 yyyy-MM-dd -->
<el-popover
placement="right"
width="200"
trigger="hover"
:disabled="formatSchedule(data).length<3"
>
<el-col :span="10" v-for="(item, index) in formatSchedule(data)" :key="index">{{item}}</el-col>
<div slot="reference" style="height: 100%;overflow: hidden;">
<p class="">{{ data.day.split('-').slice(2).join('-') }}</p>
<p>{{formatSchedule(data)[0]}}</p>
<p>{{formatSchedule(data)[1]}}</p>
<p v-if="formatSchedule(data).length>2">...</p>
</div>
</el-popover>
</template>
</el-calendar>
this.calendarData = [
{ day:'2020-10-01',drivers:['小明','高翔']},
{ day:'2020-10-03',drivers:['小明']},
{ day:'2020-10-31',drivers:['小明','高翔','戴绍华','小明','高翔','戴绍华','小明','高翔','戴绍华','小明','高翔','戴绍华']},
]
computed: {
formatSchedule() {
return data => {
if(!this.calendarData) return []
let drivers = [];
this.calendarData.forEach(item => {
if(item.day == data.day){
drivers = item.drivers
}
});
return drivers
}
}
},
watch: {
value: function() {
let month = this.value.getMonth() + 1;
//点击上下月
if(month!=this.lastMonth){
this.lastMonth = month
}
},
lastMonth:function(){
let year = this.value.getFullYear();
let month = this.value.getMonth() + 1;
if (month >= 1 && month <= 9) {
month = "0" + month;
}
this.searchData.time = (year+'-'+month)
this.searchList()//切换月份,重新请求数据
}
},
效果: