data(){ return{ data1: [] } }, created() { this.dsdd(7) }, methods:{ getDay(day) { var today = new Date(); var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day; today.setTime(targetday_milliseconds); var tYear = today.getFullYear(); var tMonth = today.getMonth(); var tDate = today.getDate(); tMonth = this.doHandleMonth(tMonth + 1); tDate = this.doHandleMonth(tDate); let weeks = { "0":'星期日', "1":'星期一', "2":'星期二', "3":'星期三', "4":'星期四', "5":'星期五', "6":'星期六', } // return tYear+"-"+tMonth+"-"+tDate; //年月日 let date = new Date(tYear+"-"+tMonth+"-"+tDate); let weekIndex = date.getDay(); let dateObj = { week: weeks[weekIndex], date : tMonth + "月" + tDate + '日' } return dateObj //月日 }, doHandleMonth(month) { var m = month; if (month.toString().length == 1) { m = "0" + month; } return m; }, dsdd(e) { //拼接 this.data1.splice(0);//请控之前的数据 for (let i = 0; i < e; i++) { this.data1.push(this.getDay(i));//-i 代表之前 i代表将来 } console.log(this.data1, '最后得到的日期数组') } }