本文主要是介绍【VUE3 element时间选择器默认选择七天】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
VUE3 element时间选择器默认选择七天
<el-date-pickerv-model="form.timeRange"type="datetimerange"start-placeholder="开始时间"end-placeholder="结束时间"format="YYYY-MM-DD HH:mm:ss"date-format="YYYY/MM/DD ddd"time-format="A hh:mm:ss"
/>
//搜索数据
const form = reactive({timeRange:[], // 时间范围,startTime: '',endTime: ''
})
onMounted(() => {form.timeRange = getNowTime()......
})
//默认选中近七天
function getNowTime() {// let that=thisconst end = new Date();const start = new Date();start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);// console.log([start, end])form.startTime= formatDate(start);form.endTime = formatDate(end);return [start, end]
}
// 时间格式化
function formatDate(date) {var myyear = date.getFullYear();var mymonth = date.getMonth() + 1;var myweekday = date.getDate();var h = date.getHours();if (mymonth < 10) {mymonth = "0" + mymonth;}if (myweekday < 10) {myweekday = "0" + myweekday;}h = h < 10 ? "0" + h : h;var m = date.getMinutes();m = m < 10 ? "0" + m : m;var s = date.getSeconds();s = s < 10 ? "0" + s : s;return (myyear + "-" + mymonth + "-" + myweekday + " " + h + ":" + m + ":" + s);
}
-------------看不明白可付费解答(¥20/次,没能解决问题不收费)------------------------
这篇关于【VUE3 element时间选择器默认选择七天】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!