我正在尝试在客户端加载两个 day.js
插件。但它似乎不起作用......我做错了什么?
哈巴狗/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))
控制台
输出
dayjs.max()
Uncaught TypeError: dayjs.max is not a function
加载的js
插件文件来自:
最佳答案
这是一个在index.html 文件中的工作示例,您可以在根Pug/Jade 文件中执行相同的操作。另外,我使用的是 cdn 版本,但您也可以从下载它们的文件夹中导入它们。
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/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a7c3c6decdd4e796899f899596" rel="noreferrer noopener nofollow">[email protected]</a>/dayjs.min.js"></script>
<script src="https://unpkg.com/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5733362e3d241766796f796566" rel="noreferrer noopener nofollow">[email protected]</a>/plugin/isBetween.js"></script>
<script src="https://unpkg.com/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="187c7961726b58293620362a29" rel="noreferrer noopener nofollow">[email protected]</a>/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>
这就是结果:
关于javascript - 如何在浏览器中加载day.js插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64319169/