1.选择某一天
代码:
<el-date-pickerv-model="invoice_date"type="date"placeholder="请选择日期"style="width: 200px;"clearable
/>
运行效果:
问题所在:这个数据的格式不是我们后端需要的那种,应该转为2025-03-15这样的格式。
下面就处理这个数据变成我们期望的格式:
// 将字符串转换为 Date 对象
const newDate = new Date(invoice_date.value);//invoice_date.value就是原数据。
// 获取年、月、日
const year = newDate.getFullYear();
const month = String(newDate.getMonth() + 1).padStart(2, '0'); // 月份从 0 开始,所以需要加 1
const day = String(newDate.getDate()).padStart(2, '0');
// 拼接为 YYYY-MM-DD 格式
const formattedDate = `${year}-${month}-${day}`;//formattedDate 就是2025-03-15这样格式的数据。
运行效果: