【问题标题】:EditorJS not showing up? How to fix this?EditorJS 没有出现?如何解决这个问题?
【发布时间】:2022-02-15 13:04:10
【问题描述】:

我正在创建一个博客。在这里,我使用 EditorJS 作为我的博客文章编辑器。我正在使用 nodejs、express 和 ejs。我在屏幕上看不到 EditorJS 界面。 这是我的代码。

app.js 的代码:

const express = require('express')
const app = express()

app.use(express.json())
app.set('view engine', 'ejs')

app.get('/', function(req, res) {
    res.render('index.ejs')
})

app.listen(3000, function(){
    console.log('Server is running on port 3000.')
})

index.ejs 文件的代码:

<!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 | Editor JS</title>
</head>

<body>
    <form action="/create-post" method="POST">
        <label for="title">Title</label>
        <input type="text" class="form-control" name="title" placeholder="Title" required>
        <label for="content">Content</label>
        <input type="text" id="editorjs" name="content" placeholder="Content" required>
        <button type="submit">Create</button>
    </form>

    <script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"></script>
    <script>
        const editor = new EditorJS('editorjs')
    </script>
    </body>
</html>

如何让EditorJS界面出现在ejs文件中?

【问题讨论】:

    标签: node.js express ejs editorjs


    【解决方案1】:

    错误消息会很有帮助。

    您是否启动了快递服务器?您的 app.js 似乎缺少 app.listen(8080);

    您的 app.get() 调用也缺少右括号。

    以下代码对我有用:

    const express = require('express')
    const app = express()
    
    app.use(express.json())
    app.set('view engine', 'ejs')
    
    app.get('/', function(req, res) {
        res.render('index.ejs')
    })
    
    app.listen(8080);
    

    您是否正确安装了 express 和 ejs? npm i -s ejs express

    此外,视图引擎似乎希望您的 ejs 文件位于“views”文件夹中。当您在浏览器中打开该页面时,如果仍然无法正常工作,您应该会看到一条错误消息。

    【讨论】:

    • 我已经修复了这些错误。但是仍然没有出现 EditorJS 界面。
    • 那么当您在浏览器中打开localhost:8080 时,您会看到什么?
    • 当我打开 localhost 时,我看到了this
    【解决方案2】:

    经过多次研究我发现,如果我使用&lt;div id="editorjs"&gt;&lt;/div&gt;,而不是使用&lt;input id="editorjs"&gt;,会出现EditorJS界面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-07
      • 1970-01-01
      • 2023-01-22
      • 2022-06-11
      • 1970-01-01
      • 2022-09-27
      相关资源
      最近更新 更多