element-plus 日期选择器数据格式修改

75 阅读1分钟

由原来的这种形式

image.png

变成这种形式

image.png

注意日期选择后时间是会自动提前一天的,下面的方法会弥补这个bug

123.gif

const dateFormate = computed(() => {
  return disabledRangeDate.value.map((date) => {
    const currentDate = new Date(date);
    currentDate.setDate(currentDate.getDate() + 1);
    return currentDate.toISOString().split('T')[0];
  });
});
  • 这里面的disabledRangeDate使我们需要修改的格式,也就是使用v-model绑定在el-data-picker上的数据
  • dateFormate是我们转换后的日期格式
  • 可以选择不使用计算属性,可以写成方法