element-ui设置日期选择,并给日期范围赋默认值
<el-form-item label="时间" prop="dateRange"> <el-date-picker v-model="queryParams.dateRange" type="daterange" range-separator="至" start-placeholder="开始日期" :picker-options="pickerBeginDateBefore" end-placeholder="结束日期" size="small" class="margin-right-10" > </el-date-picker> </el-form-item>
created() { this.getProjects(); // 设置开始日期为前30天,结束日期是当前日期,注意使用$set来设置! let startDate = this.getThreeDaysAgo(); let endDate = this.getToday(); this.$set(this.queryParams, "dateRange", [startDate, endDate]); },
// 获取当前日期 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; }, // 获取三十天之前的日期 getThreeDaysAgo() { let myDate = new Date(); let lw = new Date(myDate - 1000 * 60 * 60 * 24 * 30); //最后一个数字30可改,30天的意思 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; },
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通