要根据const currentDate = new Date();设置时间格式,而不使用moment.js,你可以使用Vue filter来实现。

首先,在你的Vue组件中,定义一个filter来格式化日期。例如:

filters: {
  formatDate: function (value) {
    const date = new Date(value);
    const year = date.getFullYear();
    const month = (date.getMonth() + 1).toString().padStart(2, '0');
    const day = date.getDate().toString().padStart(2, '0');
    return `${year}-${month}-${day}`;
  }
}

然后,在模板中使用该filter来格式化日期。例如:

<template>
  <div>
    <p>{{ currentDate | formatDate }}</p>
  </div>
</template>

这样,currentDate变量的日期就会以YYYY-MM-DD的格式显示出来。

注意:这只是一个简单的示例,你可以根据自己的需求进行定制化

vue antd 根据const currentDate = new Date;设置时间格式不使用momentjs

原文地址: https://www.cveoy.top/t/topic/ibNc 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录