[英]How to load day.js plugin in browser
I'm trying to load two day.js
plugins on the client-side.我正在尝试在客户端加载两个day.js
插件。 But it doesn't seem to be working... what am I doing wrong?但它似乎不起作用......我做错了什么?
Pug / Jade
file Pug / Jade
文件
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 console
输出
dayjs.max()
Uncaught TypeError: dayjs.max is not a function
The loaded js
plugin files are from:加载的js
插件文件来自:
https://unpkg.com/dayjs@1.9.1/plugin/isBetween.js https://unpkg.com/dayjs@1.9.1/plugin/isBetween.js
https://unpkg.com/dayjs@1.9.1/plugin/minMax.js https://unpkg.com/dayjs@1.9.1/plugin/minMax.js
Here is a working example inside a index.html file, you could do the same inside your root Pug/Jade file.这是 index.html 文件中的一个工作示例,您可以在根 Pug/Jade 文件中执行相同操作。 Also i'm using cdn version, but you could also import them from your folder where you downloaded them.此外,我使用的是 CDN 版本,但您也可以从下载它们的文件夹中导入它们。
window.dayjs_plugin_minmax
vs window.dayjs_plugin_minMax
might the problem window.dayjs_plugin_minmax
与window.dayjs_plugin_minMax
可能是问题所在
<!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.com/dayjs@1.8.21/dayjs.min.js"></script>
<script src="https://unpkg.com/dayjs@1.8.21/plugin/isBetween.js"></script>
<script src="https://unpkg.com/dayjs@1.8.21/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.org/docs/en/plugin/loading-into-browser https://day.js.org/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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.