效果就是上图

代码贴出

1.在components > calander > index.vue

<template>
<div class="page" v-if="show">
<div class="box">
<div class="box_head" v-if="!propshow">
<div class="font28" @click="calanderShowData">取消</div>
<div class="font28" @click="calanderSubmit">确定</div>
</div> <div class="box-flex">
<div class="flex-item item-content-current-day item-content-tit">
<div class="item-content titleHead">{{currentDate}}</div>
</div>
</div>
</div>
<div class="box-flex">
<div class="flex-item">
<div class="item-content">一</div>
</div>
<div class="flex-item">
<div class="item-content">二</div>
</div>
<div class="flex-item">
<div class="item-content">三</div>
</div>
<div class="flex-item">
<div class="item-content">四</div>
</div>
<div class="flex-item">
<div class="item-content">五</div>
</div>
<div class="flex-item">
<div class="item-content">六</div>
</div>
<div class="flex-item">
<div class="item-content">日</div>
</div>
</div>
<div class="box-flex">
<div class="flex-item flexData" v-for='(item, index) in currentDayList' :key='item' @click='itemFun(item.num,mouth[index],index, "first", item.state)' :class="{'hover-date': Section[index] && item.num, 'noBack': !item.state && item.num && !propshow }">
<div class="item-content red-background" v-if='currentDay === item.num && mouth[index].mouth === currentMouth.mouth && currentMouth.year === mouth[index].year' :class="{'hoverColorData' : Section[index] && item.num, 'hover-date':active[index]}">
<p>今天</p>
<p v-if="item.number && propshow">{{item.number}}展位</p>
</div>
<div class="item-content backgroundData" v-else :class="{'hover-date':active[index]}" >
<p>{{item.num}}</p>
<p v-if="item.number && propshow">{{item.number}}展位</p>
</div>
</div>
</div>
<div class="box">
<div class="box-flex">
<div class="flex-item item-content-current-day item-content-tit">
<div class="item-content titleHead">{{currentDateTwo}}</div>
</div> </div>
</div>
<div class="box-flex">
<div class="flex-item">
<div class="item-content">一</div>
</div>
<div class="flex-item">
<div class="item-content">二</div>
</div>
<div class="flex-item">
<div class="item-content">三</div>
</div>
<div class="flex-item">
<div class="item-content">四</div>
</div>
<div class="flex-item">
<div class="item-content">五</div>
</div>
<div class="flex-item">
<div class="item-content">六</div>
</div>
<div class="flex-item">
<div class="item-content">日</div>
</div>
</div>
<div class="box-flex">
<div class="flex-item flexData" v-for='(item, index) in currentDayListData' :key='item' @click='itemFun(item.num,mouths[index],index, "last", item.state)' :class="{'hover-date': Sections[index] && item.num, 'noBack': !item.state && item.num && !propshow}">
<div class="item-content backgroundData" :class="{'hover-date':actives[index]}">
<p>{{item.num}}{{item.number}}</p>
<p v-if="item.number && propshow">{{item.number}}展位</p>
</div>
</div>
</div> <div v-if="propshow" class="propshowData"></div>
</div>
</template> <script>
import vue from 'vue'
export default {
name: 'calander',
data () {
return {
calanderList: [],
show: false,
currentDate: '2017年05月03日',
currentDateTwo: '2017年06月03日',
dayList: '',
currentDayList: [],
currentObj: '',
currentDay: '',
mouth: [],
currentMouth: null,
hoverDate: {'date': null, 'mouth': null, 'year': null},
activeClick: 0,
active: [],
actives: [],
Section: [],
firstIndex: 0,
lastIndex: 0,
currentDayListData: [],
currentJudge: false,
currentObjNew: '',
Sections: [],
lastType: '',
fristType: '',
numArray: [],
numArrayTwo: []
}
},
props: {
propshow: false,
boothArray: [], // 从父级传来的数组参数,主要是传来天中携带的number展位参数
calanderList: [],
yearAndmouthFirst: {},
yearAndmouthTwo: {},
calanderShow: false
},
mounted () {
this.definedMon()
},
methods: {
definedMon(){
let timeData = this.getNextMonth(new Date(),1)
var currentObj = this.getCurrentDayString()
this.currentDate = currentObj.getFullYear() + '年' + (currentObj.getMonth() + 1) + '月' + currentObj.getDate() + '日'
this.currentDateTwo = timeData.getFullYear() + '年' + (timeData.getMonth() + 1) + '月' + timeData.getDate() + '日' this.currentDay = currentObj.getDate() this.currentObj = currentObj
this.currentMouth = {
mouth: currentObj.getMonth() + 1,
year: currentObj.getFullYear()
} setTimeout(() => {
console.log(69999999999)
this.setSchedule(currentObj, 'newMonth')
this.setSchedule(this.getNextMonth(new Date(),1), 'nextMonth')
},100);
},
monthDay: function (year, month) {
month = parseInt(month, 10);
var d = new Date(year, month, 0); //这个是都可以兼容的
var date = new Date(year + "/" + month + "/0") //IE浏览器可以获取天数,谷歌浏览器会返回NaN
return d.getDate();
},
getNextMonth: function (date,length) {
let yy = date.getFullYear()
let mm = date.getMonth()
let dd = date.getDate() let nm= 0//目标月份
nm = mm+length
let nd = 0//目标天数
if(this.monthDay(yy,nm+1)<dd){
nd = this.monthDay(yy,nm+1)
}else{
nd = dd-1
} date.setDate(1)
date.setMonth(nm)
date.setDate(nd)
return date
},
calanderSubmit(){
this.$emit('assignment', this.numArray)
},
calanderShowData(){
this.$emit('calanderShowClick', this.calanderShow)
},
formatTwo (n) {
if (n >= 10) return n
else return '0' + n
},
// 判断日历的当前日期是否不可点击
isDisabled (calander, index, item) {
// if (new Date(calander).getTime() < new Date().getTime()) {
// this.mouth[index].state = 'disabled'
// return false
// }
},
getWeekDayNextMonth(){
var myDate = new Date()
myDate.setMonth(myDate.getMonth() + 1);
myDate.setDate(1);
var weekDay=new Array(7, 1, 2, 3, 4, 5, 6)
return weekDay[myDate.getDay()];
},
itemFun (item, yearAndmouth, index, type, stateClick) {
if (stateClick) {
let dataD = new Date();
let curMonthDays = new Date(dataD.getFullYear(), (dataD.getMonth()+1), 0).getDate()
this.hoverDate = {'date': item, 'mouth': yearAndmouth.mouth, 'year': yearAndmouth.year} if (type == 'first') {
var activeArrayData = this.active
var SectionArrayData = this.Section
} else {
var activeArrayData = this.actives
var SectionArrayData = this.Sections
}
var delceIndex = -1
this.numArray.forEach((e, i) => {
if (yearAndmouth.year == e.year && yearAndmouth.mouth == e.mouth && item == e.date) {
delceIndex = i
}
}) if (delceIndex != -1) {
activeArrayData[index] = false
vue.set(activeArrayData, index, activeArrayData[index]) this.numArray.splice(delceIndex,1)
delceIndex = -1
return
}
this.yearAndmouthFirst = yearAndmouth
this.yearAndmouthFirst.date = item
this.activeClick = 1
this.fristType = type
this.firstIndex = item
this.yearFirst = yearAndmouth.year
this.mouthFirst = yearAndmouth.mouth activeArrayData[index] = true
vue.set(activeArrayData, index, activeArrayData[index])
this.numArray.push(this.yearAndmouthFirst)
}
},
doDay: function (e) {
var that = this
var currentObj = that.currentObj
var Y = currentObj.getFullYear()
var m = currentObj.getMonth() + 1
let newData = new Date
let newMonth=newData.getMonth()+1;
let d = currentObj.getDate()
var str = ''
if (e.currentTarget.dataset.key === 'left') {
m -= 1
if (m <= 0) {
str = (Y - 1) + '/' + 12 + '/' + d
} else {
str = Y + '/' + m + '/' + d
}
this.currentJudge = true
} else if(e.currentTarget.dataset.key === 'right') {
if (newMonth !== m) {
m += 1
if (m <= 12) {
str = Y + '/' + m + '/' + d
} else {
str = (Y + 1) + '/' + 1 + '/' + d
}
this.currentJudge = true
} else {
this.currentJudge = false
}
} else if (e.currentTarget.dataset.key === 'leftTwo'){
if (newMonth !== m) {
m -= 1
if (m <= 0) {
str = (Y - 1) + '/' + 12 + '/' + d
} else {
str = Y + '/' + m + '/' + d
}
this.currentJudge = true
} else {
this.currentJudge = false
}
} else if (e.currentTarget.dataset.key === 'rightTwo'){
m += 1
if (m <= 12) {
str = Y + '/' + m + '/' + d
} else {
str = (Y + 1) + '/' + 1 + '/' + d
}
this.currentJudge = true
}
if (this.currentJudge) {
currentObj = new Date(str)
this.currentDate = currentObj.getFullYear() + '年' + (currentObj.getMonth() + 1) + '月' + currentObj.getDate() + '日'
this.currentDateTwo = currentObj.getFullYear() + '年' + (currentObj.getMonth() + 2) + '月' + currentObj.getDate() + '日'
this.currentObjNew = currentObj.getFullYear() + '/' + (currentObj.getMonth() + 2) + '/' + currentObj.getDate() + '/' this.currentObj = currentObj
if (e.currentTarget.dataset.key == 'left' || e.currentTarget.dataset.key == 'right') {
this.setSchedule(currentObj, 'newMonth')
} else {
this.setSchedule(new Date(this.currentObjNew), 'nextMonth')
}
}
},
getCurrentDayString: function () {
var objDate = this.currentObj
if (objDate !== '') {
return objDate
} else {
var cobj = new Date()
var a = cobj.getFullYear() + '/' + (cobj.getMonth() + 1) + '/' + cobj.getDate()
return new Date(a)
}
},
setSchedule: function (currentObj, type) {
var that = this
var m = currentObj.getMonth() + 1
var Y = currentObj.getFullYear()
var d = currentObj.getDate()
var newDate = new Date()
var newYear = newDate.getFullYear()
var newMonth = newDate.getMonth() + 1 // var dayString = Y + '/' + m + '/' + currentObj.getDate()
var currentDayNum = new Date(Y, m, 0).getDate()
var currentDayWeek = currentObj.getUTCDay() + 1 var result = currentDayWeek - (d % 7 - 1) var firstKey = result <= 0 ? 7 + result : result var currentDayListNew = [] var mouth = []
var f = 0
for (var i = 0; i < 42; i++) {
mouth[i] = {
'mouth': m,
'year': Y
}
currentDayListNew[i] = {
'num': '',
'number': '',
'state': false
}
if (i < firstKey - 1) {
currentDayListNew[i].num = ''
} else {
if (f < currentDayNum) {
currentDayListNew[i].num = f + 1
f = currentDayListNew[i].num
if (newYear == Y && newMonth == m) {
if (f >= d) {
currentDayListNew[i].state = true
}
} else {
if (f <= d) {
currentDayListNew[i].state = true
}
}
} else if (f >= currentDayNum) {
currentDayListNew[i].num = ''
}
if (this.boothArray.length > 0) {
this.boothArray.forEach((element, indexArray) => {
if (element.year == Y && element.mouth == m) {
if (element.date == currentDayListNew[i].num) {
if (String(element.number) == 0) {
currentDayListNew[i].state = false
}
currentDayListNew[i].number = String(element.number)
}
}
})
}
if (this.calanderList.length > 0) {
this.calanderList.forEach((element, indexList) => {
if (element.year == Y && element.mouth == m) {
if (element.date == currentDayListNew[i].num) {
if (type == 'newMonth') {
this.Section[i] = true
this.active[i] = true
this.numArray.push(element)
} else {
this.Sections[i] = true
this.actives[i] = true
this.numArray.push(element)
}
}
}
});
}
}
}
if (type == 'newMonth') {
that.currentDayList = currentDayListNew
that.mouth = mouth
} else {
that.currentDayListData = currentDayListNew
that.mouths = mouth
}
this.show = true
}
}
}
</script> <style scoped>
.box_head{
height: 1.173333rem /* 88/75 */;
background: #fff;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 .4rem /* 30/75 */;
border-bottom: .013333rem /* 1/75 */ solid #E5E5E5;
}
.noBack{
background: #bbb!important;
/* border-radius: 5px!important; */
}
.hoverColorData{
color: #fff!important;
}
.propshowData{
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 0;
background: rgba(0, 0, 0, 0.1);
z-index: 9999;
}
.page{
background: #fff;
position: relative;
}
.titleHead{
margin: .266667rem /* 20/75 */ 0!important;
}
.sectionBack{
background: #8A2BE2;
}
page {
background-color: #2a8cef;
background:-webkit-gradient(linear, 0 0, 0 bottom, from(#2a8cef), to(#8A2BE2));
display: flex;
flex-direction: column;
width: 100%;
flex-wrap: nowrap;
justify-content: flex-start;
align-items: stretch;
font-size: 16px;
color: #222;
}
.disabled{
color: #ccc !important;
}
.hover-date{
background: #367EED;
color: #fff !important;
border-radius: 5px;
}
.box {
display: block;
/* margin: 10px; */
border-top: .013333rem /* 1/75 */ solid #efefef;
}
.glyphicon-triangle-left img{
transform:rotate(180deg)
}
.glyphicon img{
width:12px;
height: 19px;
margin-top:15px;
}
.box-flex {
display: -webkit-box;
display: -webkit-flex;
display: flex;
flex-wrap: wrap;
padding: 0 .133333rem /* 10/75 */;
} .flex-item {
flex-flow: nowrap;
flex-grow: 1;
flex-shrink: 1;
width: 14%;
margin: 1px 1px 1px 0px;
} .item-content {
margin: 1px;
padding: 5px 1px;
text-align: center;
/* height: 45px; */
/* line-height: 45px; */
font-size:14px;
position: relative;
flex-wrap: wrap;
justify-content: center;
}
.item-content i{
width:100%;
text-align: center;
left:0;
position: absolute;
top:8px;
}
.item-content span{
width:100%;
text-align: center;
left:0;
position: absolute;
top:3px;
font-size:12px;
color: #367EED;
line-height: 1;
}
.item-content-tit{
width:30%;
/* margin: .133333rem 10/75 0; */
}
.item-content-tit .item-content{
font-size:17px;
}
.red-background{
color:#367EED;
border-radius: 5px;
} .item-content-current-day {
flex-grow: 2;
}
</style>

  

2.在页面中引用组件

<calander @assignment="assignment" :propshow="propshow" :boothArray="boothArray" :calanderList="calanderList"></calander> 

<script>
import calander from '@/components/calander'
export default {
components: {
calander
},
data() {
return {
calanderList: [],
boothArray: [],
propshow: false,
};
},
methods: {
assignment(){
// 组件调取父级方法
},
}
}
</script>

vue 日历组件只显示本月和下个月 -- 多选日期的更多相关文章

  1. bootstrap中日历组件只显示年月

    大多数情况下日历组件我们使用的都是yyyy-mm-dd的日历格式,但是有时候需求不需要我们精确到日,而是最小单位到月份(yyyy-mm),网上找了很多方法,但是都没有我想要的效果,一些属性的设置都没有 ...

  2. Vue日历组件的功能

    本来呢,开开心心的写完了这个功能,然后发现elemeng更新了,增加了日历组件这个功能 我的内心机器奔溃,但是,element的日历组件太简单了,我感觉还是手撸一个吧,毕竟也不是很难 实现了显示农历, ...

  3. vue 日历组件

    Github 上很多点击弹出日历选择某个时间的组件,却没有找到单纯展示日历并且能点击获取时间的组件 npm i vue-calendar-component --save cnpm i vue-cal ...

  4. 一个vue的日历组件

    说明: 1.基于element-ui开发的vue日历组件. 地址 更新: 1.增加value-format指定返回值的格式2.增加头部插槽自定义头部 <ele-calendar > < ...

  5. bootstrap datetimepicker 中只显示年或者只显示月份

    1.只显示datetimepicker  日历中只显示年份 $("#day-access-calendar").datepicker({ startView: 2, maxView ...

  6. vue 中 echart 在子组件中只显示一次的问题

    问题描述 一次项目开发过程中,需要做一些图表,用的是百度开源的 echarts. vue推荐组件化开发,所以就把每个图表封装成子组件,然后在需要用到该图表的父组件中直接使用. 实际开发中,数据肯定都是 ...

  7. Vue中使用Vue.component定义两个全局组件,用单标签应用组件时,只显示一个组件的问题和 $emit的使用。

    解决方法: 定义了两个 Vue.component 在 el 中使用的时候要用 双标签, 用单表标签的时候,只会显示第个 组件间 这样写只显示 welcome-button 组件 <welcom ...

  8. 在vue中使用elementUI饿了么框架使用el-calendar日历组件,实现自定义显示备忘录标注

    饿了么官网给的自定义例子是点击哪个日期在日期后面加个勾 而我们想要的是显示备忘录,像这样↓,日历上直接显示 这时候我们要把template里的代码改一下 <el-calendar> < ...

  9. vue初学实践之路——vue简单日历组件(1)

    ---恢复内容开始--- 最近做的项目有一个需求,需要有一个日历组件供预定功能使用,之前的代码过于繁琐复杂,所以我采用vue重写了这个组件. npm.vue等等安装. 只是一个简单的日历组件,所以并不 ...

随机推荐

  1. 最全的MonkeyRunner自动化测试从入门到精通(10)

    三.MonkeyRunner复杂的功能开始学习 (1)获取APK文件中ID的两种方式 Monkeyrunner的环境已经搭建完成,现在对Monkeyrunner做一个简介. Monkeyrunner工 ...

  2. GDB调试原理——ptrace系统调用

    本文由霸气的菠萝原创,转载请注明出处:http://www.cnblogs.com/xsln/p/ptrace.html 全部关于gdb的文章索引请点这里 引子: gdb基本上大家都在用,你有没有想过 ...

  3. LaTeX参考文献出现问号

    自己用LaTeX编辑,忘记在\end{document}前面放: \bibliographystyle{ieeetr}\bibliography{sample-bibliography} 导致这个现象 ...

  4. 认识Charles-proxy 抓包工具

    1.为什么不用 Fiddler 抓包工具? 在这里说明一下,因为Fiddler 抓包工具使用C#语言写的,不能在  MAC 上运行,而   Charles-proxy  他是 java  开发的,可以 ...

  5. mysql插入数据会变中文

    db.url=jdbc:mysql://192.168.0.149:3306/pack_platform_dev?useUnicode=true&characterEncoding=utf-8 ...

  6. Python加密保护解决方案

    防止代码反编译,高强度加密保护exe或pyc文件 产品简介 Python语言写的程序无需编译成二进制文件代码,可以直接从源代码运行程序.在计算机内部,Python解释器把源代码转换成字节码的中间形式, ...

  7. 8 . IO类-标准IO、文件IO、stringIO

    8.1 IO类 #include <iostream> //标准IO头文件  8.2 文件输入输出流 #include <fstream> //读写文件头文件 std::fst ...

  8. python数据结构-如何统计序列中元素的频度

    如何统计序列中元素的频度 问题举例 如何找出随机序列[1, 5, 6, 5, 3, 2, 1, 0, 6, 1, 6]中出现频度最高的3个元素? 如何统计某篇英文文章中词频最高的5个单词? 将序列转换 ...

  9. GIEC2019第六届全球互联网经济大会北京站震撼来袭!

    GIEC2019第六届全球互联网经济大会将于2019年8月26日-27日在北京召开,以“智慧零售数字商业”为主题,将邀请政府官员.企业高管.专家学者共议新形势下如何利人工智能和数字化的商业模式促进零售 ...

  10. laravel----------php7.0.12 laravel 链接sqlserver数据库

    https://www.microsoft.com/en-us/download/details.aspx?id=20098 下载最后一个,然后这个工具可以将dll扩展下载下来,选择一个空白的文件夹就 ...