javascript - How to load day.js plugin in browser - Stack Overflow

I'm trying to load two day.js plugins on the client-side. But it doesn't seem to be working..

I'm trying to load two day.js plugins on the client-side. But it doesn't seem to be working... what am I doing wrong?

Pug / Jade file

script(defer, src='javascript/external/day.js')
script(defer, src='javascript/external/day_minmax.js')
script(defer, src='javascript/external/day_isbetween.js')

script(defer, dayjs.extend(window.dayjs_plugin_minmax))
script(defer, dayjs.extend(window.dayjs_plugin_isbetween))

console output

dayjs.max()
Uncaught TypeError: dayjs.max is not a function

The loaded js plugin files are from:

/[email protected]/plugin/isBetween.js

/[email protected]/plugin/minMax.js

I'm trying to load two day.js plugins on the client-side. But it doesn't seem to be working... what am I doing wrong?

Pug / Jade file

script(defer, src='javascript/external/day.js')
script(defer, src='javascript/external/day_minmax.js')
script(defer, src='javascript/external/day_isbetween.js')

script(defer, dayjs.extend(window.dayjs_plugin_minmax))
script(defer, dayjs.extend(window.dayjs_plugin_isbetween))

console output

dayjs.max()
Uncaught TypeError: dayjs.max is not a function

The loaded js plugin files are from:

https://unpkg./[email protected]/plugin/isBetween.js

https://unpkg./[email protected]/plugin/minMax.js

Share Improve this question asked Oct 12, 2020 at 13:47 uncooluncool 2,7037 gold badges32 silver badges57 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Here is a working example inside a index.html file, you could do the same inside your root Pug/Jade file. Also i'm using cdn version, but you could also import them from your folder where you downloaded them.

window.dayjs_plugin_minmax vs window.dayjs_plugin_minMax might the problem

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>Test page</title>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <script src="https://unpkg./[email protected]/dayjs.min.js"></script>
    <script src="https://unpkg./[email protected]/plugin/isBetween.js"></script>
    <script src="https://unpkg./[email protected]/plugin/minMax.js"></script>
  </head>
  <body></body>
  <script>
    const minMax = window.dayjs_plugin_minMax;
    const isBetween = window.dayjs_plugin_isBetween;
    dayjs.extend(minMax);
    dayjs.extend(isBetween);
    console.log(
      "MAX: ",
      dayjs.max(dayjs(), dayjs("2018-01-01"), dayjs("2019-01-01"))
    );
    console.log(
      "MIN: ",
      dayjs.min(dayjs(), dayjs("2018-01-01"), dayjs("2019-01-01"))
    );
    console.log(
      "BETWEEN: ",
      dayjs("2016-10-30").isBetween("2016-01-01", "2016-10-30", null, "[)")
    );
  </script>
</html>

And this is the result:

On the official website there is a "hidden" section with example import of plugins with browser.

https://day.js/docs/en/plugin/loading-into-browser

Worked for me like as they say:

<script src="path/to/dayjs/plugin/advancedFormat"></script>
<!-- Load plugin as window.dayjs_plugin_NAME -->
<script>
  dayjs.extend(window.dayjs_plugin_advancedFormat)
</script>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745531014a4631693.html

相关推荐

  • javascript - How to load day.js plugin in browser - Stack Overflow

    I'm trying to load two day.js plugins on the client-side. But it doesn't seem to be working..

    16小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信