1、在表单中引入组件
a-form ref="formRef" :model="InfoModel">
<a-row :gutter="16">
<a-col :span="12">
<a-form-item label="离开时间:" name="leaveTime">
<a-date-picker showTime valueFormat="YYYY-MM-DD HH:mm:ss" v-model:value="InfoModel.leaveTime" />
</a-form-item>
</a-col>
</a-row>
</a-form>
const InfoModel = reactive({
leaveTime: '',
});
2、将当前时间赋给组件绑定的属性
const currentDate = new Date();
const formattedTime = currentDate.toISOString().split('T')[0] + ' ' + currentDate.toTimeString().split(' ')[0];
InfoModel.leaveTime = formattedTime;
console.log('现在的时间', InfoModel.leaveTime);
3、当打开表单时就会默认显示当前的时间