简体   繁体   English

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

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

I am creating a blog.我正在创建一个博客。 Here I am using EditorJS as my blog-post editor.在这里,我使用 EditorJS 作为我的博文编辑器。 I am using nodejs, express and ejs.我正在使用 nodejs、express 和 ejs。 I can't see the EditorJS interface on my screen.我在屏幕上看不到 EditorJS 界面。 Here is my code.这是我的代码。

code for app.js : 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.')
})

code for index.ejs file: 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>

How to make the EditorJS interface to be appeared in the ejs file?如何让EditorJS界面出现在ejs文件中?

An error message would be helpful.错误消息会有所帮助。

Did you start your express server?你启动了你的快速服务器吗? Your app.js seems to be missing app.listen(8080);你的 app.js 似乎缺少app.listen(8080);

Also your app.get() call is missing the closing bracket.您的 app.get() 调用也缺少右括号。

The following code is working for me:以下代码对我有用:

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);

Did you install express and ejs correctly?你是否正确安装了 express 和 ejs? npm i -s ejs express

Also the view engine seems to expect your ejs-files to be in the "views" folder.此外,视图引擎似乎希望您的 ejs 文件位于“views”文件夹中。 When you open the page in your browser, you should see an error message if it is still not working.当您在浏览器中打开该页面时,如果它仍然无法运行,您应该会看到一条错误消息。

After several researches I found that, instead of using <input id="editorjs"> if I use <div id="editorjs"></div> , EditorJS interface shows up.经过多次研究,我发现,如果我使用<div id="editorjs"></div>而不是使用<input id="editorjs"> > ,则会显示 EditorJS 界面。

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

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