element|element ui日期组件设置默认时间

对日期进行了预处理(将起始的默认时间设置为当前时间,结束时间的默认时间设置为往一个月后),即使是点击了时间也不会报错
运行图效果
element|element ui日期组件设置默认时间
文章图片

【element|element ui日期组件设置默认时间】vue文件

> export default { data() { return { startTime: "", endTime: "", nextTime: "", } }, methods: { getStartTime() { // 获取其当前月的第一天 var data = https://www.it610.com/article/new Date() var Da = new Date(data.getTime()) var y = Da.getFullYear() var m = Da.getMonth() + 1 m = m < 10 ?"0" + m : m return y + "-" + m + "-" + "01" + " " + "00" + ":" + "00" + ":" + "00" }, getEndTime() { var data = https://www.it610.com/article/new Date() var Da = new Date(data.getTime()) var y = Da.getFullYear() var m = Da.getMonth() + 1 var d = Da.getDate() var H = Da.getHours() var mm = Da.getMinutes() var ss = Da.getSeconds() m = m < 10 ?"0" + m : m d = d < 10 ? "0" + d : d H = H < 10 ? "0" + H : H return y + "-" + m + "-" + d + " " + H + ":" + mm + ":" + ss }, getnextTime() { var data = https://www.it610.com/article/new Date() var Da = new Date(data.getTime() + 24 * 60 * 60 * 1000 * 30) var y = Da.getFullYear() var m = Da.getMonth() + 1 var d = Da.getDate() var H = Da.getHours() var mm = Da.getMinutes() var ss = Da.getSeconds() m = m < 10 ?"0" + m : m d = d < 10 ? "0" + d : d H = H < 10 ? "0" + H : H return y + "-" + m + "-" + d + " " + H + ":" + mm + ":" + ss }, find() { console.log(this.startTime, this.endTime, this.nextTime) }, }, mounted() { var vm = this vm.startTime = vm.getStartTime() vm.endTime = vm.getEndTime() vm.nextTime = vm.getnextTime() }, }

    推荐阅读