我试图在网页浏览器上显示一个简单的通知,使用的是PNotify上的thymeleaf html页面。
我在我的pom.xml中添加了下面的webjar。
<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我已通过检查浏览器确认该文件存在于core/5.2.0/dist/PNotify.js
我毫无头绪,在论坛上找不到任何帮助。有谁能帮我,分享一下调试的指点吗?
发布于 2022-01-29 19:21:23
最后,我能够通过进行以下更改来使其正常工作。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.'
});https://stackoverflow.com/questions/70902730
复制相似问题