vue根据yyyy-mm-dd获取星期几

<span>{{dayData}}</span>{{xqj}}
<el-date-picker v-model="dayData" clearable style="width: 200px;margin-right: 10px;" type="date" value-format="yyyy-MM-dd" :picker-options="pickerOptions0" placeholder="请选择时间" @change="handleChange"></el-date-picker>
	

data定义数据

data() {
			return {
				xqj:'',//星期几
				dayData: '', //时间
				// 选择今天以及今天以前的日期
				pickerOptions0: {
					disabledDate(time) {
						return time.getTime() > Date.now() - 8.64e6
					}
				},
				
			}
		},

creates初始化

created() {
			//默认时间
			this.dayData = this.getNowDate();
			//初始化星期几
			this.xqj = this.getDateWeek(this.dayData);
			
		},

methods:


getDateWeek (date) {
			  const weekDay = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
			  const myDate = new Date(Date.parse(date))
			  return weekDay[myDate.getDay()]
			},
			// 切换日期
            handleChange(value) {
				this.xqj = this.getDateWeek(value);
			},
			//查询当天日期
			getNowDate() {
				const timeOne = new Date()
				const year = timeOne.getFullYear()
				let month = timeOne.getMonth() + 1
				let day = timeOne.getDate()
				month = month < 10 ? '0' + month : month
				day = day < 10 ? '0' + day : day
				const NOW_MONTHS_AGO = `${year}-${month}-${day}`
				return NOW_MONTHS_AGO
			},
			

你可能感兴趣的:(vue.js,前端,javascript)