element-ui日期组件默认赋值
<el-date-picker v-model="form.regDateBeg" type="date" value-format="yyyy-MM-dd" placeholder="开始日期"></el-date-picker>var faiSearchObj = new Vue({el: '.fai-payRecord-search',data: {...
·
<el-date-picker v-model="form.regDateBeg" type="date" value-format="yyyy-MM-dd" placeholder="开始日期"></el-date-picker>
var faiSearchObj = new Vue({
el: '.fai-payRecord-search',
data: {
form: {
regDateBeg: dateFormatter(new Date(), false),//这个日期参数,这里做了修改
...(其他无关参数,省略)
}
},
methods: {
onSubmit() {
console.log(this.form.regDateBeg);
}
}
});
function dateFormatter(str){//默认返回yyyy-MM-dd HH-mm-ss
var hasTime = arguments[1] != false ? true : false;//可传第二个参数false,返回yyyy-MM-dd
var d = new Date(str);
var year = d.getFullYear();
var month = (d.getMonth()+1)<10 ? '0'+(d.getMonth()+1) : (d.getMonth()+1);
var day = d.getDate()<10 ? '0'+d.getDate() : d.getDate();
var hour = d.getHours()<10 ? '0'+d.getHours() : d.getHours();
var minute = d.getMinutes()<10 ? '0'+d.getMinutes() : d.getMinutes();
var second = d.getSeconds()<10 ? '0'+d.getSeconds() : d.getSeconds();
if(hasTime){
return [year, month, day].join('-') + " " + [hour, minute, second].join(':');
}else{
return [year, month, day].join('-');
}
}
更多推荐
已为社区贡献5条内容
所有评论(0)