簡體   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