0

我正在尝试在 thymeleaf html 页面上使用PNotify在网络浏览器上显示一个简单的通知。

我已将以下 webjar 添加到我的 pom.xml 中。

<dependency>
        <groupId>org.webjars.npm</groupId>
        <artifactId>pnotify__core</artifactId>
        <version>${pnotify.version}</version>
</dependency>
<dependency>
        <groupId>org.webjars.npm</groupId>
        <artifactId>pnotify__mobile</artifactId>
        <version>${pnotify.version}</version>
</dependency>

PNotify 版本 = 5.2.0

在我的 HTML 中,我包含了 -

<link th:href="@{/webjars/pnotify__core/dist/PNotify.css}" rel="stylesheet" />
<link th:href="@{/webjars/pnotify__mobile/dist/PNotifyMobile.css}" rel="stylesheet" />
<script th:src="@{/webjars/pnotify__core/dist/PNotify.js}"></script>
<script th:src="@{/webjars/pnotify__mobile/dist/PNotifyMobile.js}"></script>

我已经确认所有这些资源都正确加载了 200 状态代码。在我的 javascript 中,我正在尝试执行以下操作 -

<script type="module">
    import { defaultModules } from '../webjars/pnotify__core/5.2.0/dist/PNotify.js';
</script>

但是,我在浏览器控制台中收到以下错误

Uncaught SyntaxError: import not found: defaultModules

我通过检查浏览器确认该文件存在于 http://localhost:8080/webjars/pnotify__core/5.2.0/dist/PNotify.js

我一无所知,在论坛中找不到任何帮助。有人可以帮助我并分享一些调试指南吗?

4

1 回答 1

0

最后,我能够通过进行以下更改来使其正常工作。pom.xml 中的依赖关系是相同的。在 HTML 文件中,添加了以下 css 和 js

<link th:href="@{/webjars/pnotify__core/dist/PNotify.css}" rel="stylesheet" />
<link th:href="@{/webjars/pnotify__bootstrap4/dist/PNotifyBootstrap4.css}" rel="stylesheet" />
<script th:src="@{/webjars/pnotify__core/dist/PNotify.js}"></script>
<script th:src="@{/webjars/pnotify__bootstrap4/dist/PNotifyBootstrap4.js}"></script>

在 javascript 中,使用了以下代码片段(没有任何导入)

PNotify.defaultModules.set(PNotifyBootstrap4, {});
PNotify.success({
    title: 'Success!',
    text: 'That thing that you were trying to do worked.'
});
于 2022-01-29T19:21:23.313 回答