elementui 周选择器 获取周一到周五的日期 和当前是多少年多少周
<el-form-item><el-date-picker v-model="query.cycle" type="week" placeholder="选择周" format="yyyy 第 WW 周":picker-options="{ firstDayOfWeek: 1 }" @change="weekChange"></el-date-picker></el-form-item>
利用Moment.js
weekChange(val) {let weekOfDay = moment(val).format("E");let lastMonday = moment(val).subtract(weekOfDay - 1, "days").format("YYYY-MM-DD");//周一日期let lastTuesday = moment(val).subtract(weekOfDay - 2, "days").format("YYYY-MM-DD");//周二日期let lastWedday = moment(val).subtract(weekOfDay - 3, "days").format("YYYY-MM-DD");//周三日期let lastThurday = moment(val).subtract(weekOfDay - 4, "days").format("YYYY-MM-DD");//周四日期let lastFriday = moment(val).subtract(weekOfDay - 5, "days").format("YYYY-MM-DD");//周五日期let year = moment(val).utcOffset("+08:00").format('yyyy') //年let week = moment(val).utcOffset("+08:00").format('WW') //周console.log(lastMonday, lastTuesday, lastWedday, lastThurday, lastFriday, year, week);},
打印如下: