vue el-date-picker 默认日期为当天
【代码】vue el-date-picker 默认日期为当天。
·
page
<el-form-item>
<el-date-picker
:size="size"
v-model="dataTime"
value-format="yyyy-MM-dd HH:mm:ss"
type="datetimerange"
@change="handleChangeDate"
range-separator="~"
start-placeholder="订单开始时间"
end-placeholder="订单结束时间"
>
</el-date-picker>
</el-form-item>
js
data () {
dataTime: '',
filters: { //查询条件
orderTimeStart: '',
orderTimeEnd: '',
},
}
// 默认 当日
getTestTime () {
let isDate = new Date()
let sTime = `${isDate.getFullYear()}-${isDate.getMonth() + 1}-${isDate.getDate()}`
let eTime = `${isDate.getFullYear()}-${isDate.getMonth() + 1}-${isDate.getDate()}`
sTime = `${sTime} 00:00:00`
eTime = `${eTime} 23:59:59`
this.dataTime = [new Date(sTime), new Date(eTime)] // 显示的默认时间
this.filters.orderTimeStart = sTime //查询 赋值
this.filters.orderTimeEnd = eTime
},
// 改变时间
handleChangeDate (e) {
if (e) {
this.filters.orderTimeStart = e[0]
this.filters.orderTimeEnd = e[1]
} else {
this.filters.orderTimeStart = ''
this.filters.orderTimeEnd = ''
}
},
mounted () {
this.getTestTime() //先调用默认时间
this.findPage(null) //在调页面查询 此方法省略
}
更多推荐
已为社区贡献6条内容
所有评论(0)