【问题标题】:How to configure @nuxtjs/moment to use relativeTime settings for en locale如何配置 @nuxtjs/moment 以使用相对时间设置为 en locale
【发布时间】:2020-09-01 05:50:33
【问题描述】:
  • 我正在尝试使用 moment(...).fromNow() 显示相对时间
  • 我正在使用@nuxtjs/moment 模块
  • 目前显示相对时间为“15 天前”等。我想将其更改为“15 天”

按照THIS answer目前是怎么做的

moment.updateLocale('en', {
    relativeTime : {
        future: "in %s",
        past:   "%s ago",
        s: function (number, withoutSuffix, key, isFuture){
            return '00:' + (number<10 ? '0':'') + number + ' minutes';
        },
        m:  "01:00 minutes",
        mm: function (number, withoutSuffix, key, isFuture){
            return (number<10 ? '0':'') + number + ':00' + ' minutes';
        },
        h:  "an hour",
        hh: "%d hours",
        d:  "a day",
        dd: "%d days",
        M:  "a month",
        MM: "%d months",
        y:  "a year",
        yy: "%d years"
    }
});

如何将它应用到@nuxtjs/moment 模块

【问题讨论】:

    标签: momentjs nuxt.js relative-time-span


    【解决方案1】:

    制作一个 nuxt 插件并使用上下文访问 $moment

    export default (context) => {
      context.$moment.updateLocale('en', {
        relativeTime: {
          future: '%s',
          past: '%s',
          s: '1 s',
          ss: '%d seconds',
          m: '1 m',
          mm: '%d m',
          h: '1 h',
          hh: '%d h',
          d: '1 d',
          dd: '%d d',
          M: '1 M',
          MM: '%d M',
          y: '1 Y',
          yy: '%d Y',
        },
      })
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-16
      • 2012-02-11
      • 1970-01-01
      • 2021-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-23
      相关资源
      最近更新 更多