Project scenario:
Project scenario: The default el-date-picker component time is displayed in the format of the time interval range from the beginning of the month to the end of the month
solution:
1. HTML code
<el-date-picker
v-model="value"
type="daterange"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
value-format="yyyyMMdd"
>
</el-date-picker>
2. js code
data() {
return {
value: [],
};
},
//懒得封装方法,直接写生命周期里了,习惯代码规范的可以自行封装放入方法
created() {
//查询当前月份月初到月末
let myDate = new Date();
let month = myDate.getMonth() + 1;
month = month < 10 ? "0" + month : month; //格式化月份,补0
let statDateStart = myDate.getFullYear().toString() + month + "01"; //月初
let dayEnd = new Date(myDate.getFullYear(), month, 0).getDate(); //获取当月一共有多少天
let statDateEnd = myDate.getFullYear().toString() + month + dayEnd; //月末
console.log(statDateStart); //20230101
console.log(statDateEnd); //20230131
this.value.push(statDateStart, statDateEnd);
},