效果
代码:
html代码:
<div class="week-item" v-on:click="dateActive(index)" v-for="(day,index) in week" v-bind:class="{ active:index==current}">
<div class="week-date">{{day.ts}}</div>
<div class="week-name">{{day.xq}}</div>
</div>
方法:
data: {
current 0;//控制样式切换
week: [],//初始为空
}
created: function () {
var currentTime = new Date();
var nowDayOfWeek = currentTime.getDay();//当前周的第几天
var nowDay = currentTime.getDate();//当前日
var nowMonth = currentTime.getMonth();//当前月
var nowYear = currentTime.getFullYear();//当前年
currentTime = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek + 1);//完整日期
var weeks = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"]
for (var i = 0; i < 7; i++) {
if (i == 0) {
currentTime = currentTime.setDate(currentTime.getDate());
} else {
currentTime = currentTime.setDate(currentTime.getDate() + 1);
}
currentTime = new Date(currentTime);
var currentDays = currentTime.getDate();
var currentMon = currentTime.getMonth() + 1;
var dateDay = currentDays//某一天
var dates = {};
dates.ts = currentMon + "-" + dateDay
dates.xq = weeks[i]
this.week.push(dates)
}
//this.weekstar = weekstar;
//this.currentMon = currentMon;
},
选中样式切换:
dateActive: function (index) {
this.current = index;
var need = this.week[index].xq//获取选中的值
console.log(need)
},