element ui el-date-picker 组件添加默认值
element ui el-date-picker 组件默认当年
<el-form-item label="">
<el-date-picker v-model="searchForm.year" dea type="year" value-format="yyyy" placeholder="请选择年度" :pickerOptions="pickerOptions">
</el-date-picker>
</el-form-item>
searchForm: {
year:new Date().getFullYear().toString(),
},
element ui el-date-picker 组件默认当前月份
<el-date-picker v-model="searchForm.month" type="month" value-format="yyyy-MM" placeholder="请选择选择月份">
</el-date-picker>
created() {
var nowDate = new Date();
var date = {
year: nowDate.getFullYear(),
month: nowDate.getMonth() + 1,
day: nowDate.getDate(),
};
const dayDate =
date.year + "-" + (date.month >= 10 ? date.month : "0" + date.month);
var date = new Date();
this.$set(this.searchForm, "month", dayDate.toString());
},
new Date() 用法
var d = new Date();
d .getFullYear(); //获取完整的年份(4位)
d .getMonth(); //获取当前月份(0-11,0代表1月)
d .getDate(); //获取当前日(1-31)
d .getDay(); //获取当前星期X(0-6,0代表星期天)
d .getTime(); //获取当前时间(从1970.1.1开始的毫秒数)
d .getHours(); //获取当前小时数(0-23)
d .getMinutes(); //获取当前分钟数(0-59)
d .getSeconds(); //获取当前秒数(0-59)
d .getMilliseconds(); //获取当前毫秒数(0-999)
d .toLocaleDateString(); //获取当前日期
var mytime=d.toLocaleTimeString(); //获取当前时间
d.toLocaleString( ); //获取日期与时间
参考文章地址:https://blog.csdn.net/coldriversnow/article/details/125635882