欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 文化 > Element UI DatePicker选择日期范围区间默认显示前一个月和本月

Element UI DatePicker选择日期范围区间默认显示前一个月和本月

2024/10/24 5:20:46 来源:https://blog.csdn.net/qq_39047060/article/details/140541990  浏览:    关键词:Element UI DatePicker选择日期范围区间默认显示前一个月和本月

要求:点击el-date-picker选择时间范围时,默认展开当月和上个月。

但是Element UI的组件默认展开的是本月和下一个月,如下图所示:

改为

<span @click="changeInitCalendarRange"><el-date-picker v-model="ruleForm.time" type="datetimerange" value-format="yyyy-MM-dd HH:mm:ss"range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions" @change="onsetmonitor" @blur="blur"class="form-width"></el-date-picker>
</span>
<script>
export default {data() {return {pickerOptions: {disabledDate(time) {return time.getTime() > Date.now() - 8.64e7 || time.getTime() < Date.now() - 8.64e7 * 90;},shortcuts: [{text: '最近一周',onClick(picker) {const end = new Date();const start = new Date();start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);picker.$emit('pick', [start, end]);},},{text: '最近一个月',onClick(picker) {const end = new Date();const start = new Date();start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);picker.$emit('pick', [start, end]);},},{text: '最近三个月',onClick(picker) {const end = new Date();const start = new Date();start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);picker.$emit('pick', [start, end]);},},],},};},methods: {/**时间范围选择器,组件默认展示上月和本月  点击判断**/changeInitCalendarRange() {if(this.countss > 0){return}else{this.countss++let element = document.querySelector("button.el-picker-panel__icon-btn.el-icon-arrow-left");if (element){element.click()};};},//多次点击清空按钮blur(){if(this.ruleForm.time == null){this.countss = 0;}},//如果选定值,重置countssonsetmonitor(){if(this.ruleForm.time){return};this.countss = 0},}
}

 

 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com