标签
<el-date-picker
v-model="dateValue"
type="daterange"
align="right"
unlink-panels
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
value-format="yyyy-MM-dd"
:picker-options="pickerOptions"
>
</el-date-picker>
JS
data() {
return {
dateValue: [],
}
}
mounted() {
let startDate = this.getThreeDaysAgo();
let endDate = this.getToday();
this.dateValue.push(startDate,endDate);
},
methods: {
getToday() {
//获取当前日期
let myDate = new Date();
let nowY = myDate.getFullYear();
let nowM = myDate.getMonth() + 1;
let nowD = myDate.getDate();
let endDate =
nowY +
"-" +
(nowM < 10 ? "0" + nowM : nowM) +
"-" +
(nowD < 10 ? "0" + nowD : nowD); //当前日期
return endDate;
},
getThreeMonAgo() {
let myDate = new Date();
let lw = new Date(myDate - 1000 * 60 * 60 * 24 * 90); //最后一个数字可改,天数
let lastY = lw.getFullYear();
let lastM = lw.getMonth() + 1;
let lastD = lw.getDate();
let startData =
lastY +
"-" +
(lastM < 10 ? "0" + lastM : lastM) +
"-" +
(lastD < 10 ? "0" + lastD : lastD);
return startData;
},
}