繁体   English   中英

EditorJS 没有出现? 如何解决这个问题?

[英]EditorJS not showing up? How to fix this?

我正在创建一个博客。 在这里,我使用 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文件中?

错误消息会有所帮助。

你启动了你的快速服务器吗? 你的 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”文件夹中。 当您在浏览器中打开该页面时,如果它仍然无法运行,您应该会看到一条错误消息。

经过多次研究,我发现,如果我使用<div id="editorjs"></div>而不是使用<input id="editorjs"> > ,则会显示 EditorJS 界面。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM