无法配置EditorJs

问题描述 投票:0回答:1

我有一个网页,我想在其中使用 EditorJs。其 html 是:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Button Example</title>
    <!-- Include Editor.js styles -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest/dist/editor.min.css" />
</head>
<body>
    <div id="starter">Application begins here!</div> 
    <div id="editorjs"></div>
    <button id="save">Save Article</button>
    <script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"></script>
    <script  type="module" src="sampler.js"></script>
</body>
</html>

sampler.js 文件如下所示:

import {EditorJS} from '@editorjs/editorjs';
import {Header} from '@editorjs/header';

const editor = new EditorJS({
    holder:"editorjs",
    tools:{
        header:{
            class:Header,
            inlineToolbar:['link']
        },
        list:{
            class:List,
            inlineToolbar:['link','bold']
        }
    }
})

let saveBtn=document.querySelector('button')

saveBtn.addEventListener('click',()=>{
    editor.save().then((outputData)=>{
        console.log(outputData)
    })
})

我正在使用 CDN 导入,那么我在sampler.js 中的导入语句应该是什么样的。目前我收到此错误:

Uncaught TypeError: Failed to resolve module specifier "@editorjs/editorjs". Relative references must start with either "/", "./", or "../"
javascript import module cdn editorjs
1个回答
0
投票

如果是CDN引用的,则不需要导入直接使用。

© www.soinside.com 2019 - 2024. All rights reserved.