
vue部分代码:
<el-date-picker :editable="false" :clearable="false" v-model="deviceFormData.time" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions" format="yyyy-MM-dd" value-format="yyyy-MM-dd"> </el-date-picker>
js部分代码:
data(){
return {
deviceFormData:{
time:[]
},
//不能选择当前日期之后的时间
pickerOptions: {
disabledDate(time) {
return time.getTime() > Date.now();
}
},
}
}
created() {
if (process.client) {
const that = this;
that.getTimeFn();
}
},
//设置默认时间
getTimeFn() {
const that = this;
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
that.deviceFormData.time[0] = that.formatDate(start);
that.deviceFormData.time[1] = that.formatDate(end);
},
//时间格式化
formatDate(date) {
var myyear = date.getFullYear();
var mymonth = date.getMonth() + 1;
var myweekday = date.getDate();
if (mymonth < 10) {
mymonth = "0" + mymonth;
}
if (myweekday < 10) {
myweekday = "0" + myweekday;
}
return myyear + "-" + mymonth + "-" + myweekday;
},
标签: el-date-picker, element-ui
上面是“element-ui时间选择器el-date-picker默认当前时间至7天之前时间”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_30937.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

数字滚动效果(兼容IE6/IE8)
Astronomy Now是英国创办最久的一份线上天文杂志
在线电子魔方官网:一个为魔方爱好者提供便捷的在线练习平台
一款提供代码审查、聊天与自动补全的全能的AI编程助手——Bito
Fun-CosyVoice3.5语音生成模型,支持13种语言,可精准调节语气、语速、语调、情绪