我想在我的项目中使用EditorJS。因此,在阅读了文档之后,我创建了一个HTML文件。以下是名为index.html的文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
</head>
<body>
<div id="editorjs"></div>
<script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"></script>
<script>
import EditorJS from '@editorjs/editorjs'
const editor = new EditorJS('editorjs')
</script>
</body>
</html>在将文件打开浏览器后,EditorJS将不会显示,该消息将打印在控制台- Uncaught SyntaxError: Cannot use import statement outside a module中。
如何解决这个问题?
发布于 2022-05-25 05:29:12
脚本不是类型模块,请使用:
<script type="module">发布于 2022-05-25 05:41:07
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"></script>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
</head>
<body>
<div id="editorjs"></div>
<script>
const editor = new EditorJS({
autofocus: true
});
</script>
</body>
</html>
当您在HTML文件中添加脚本标记时,您不需要再次导入库--您可以开始使用它了!
https://stackoverflow.com/questions/72372354
复制相似问题