From f5681fe5b18a84219aa455fafc57e54a51ef9574 Mon Sep 17 00:00:00 2001 From: laowang Date: Thu, 19 May 2022 09:10:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AF=84=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db.sql | 2 ++ modules/comment.js | 3 ++- public/detail.html | 22 ++++++++++++---------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/db.sql b/db.sql index 71cf829..76dff0d 100644 --- a/db.sql +++ b/db.sql @@ -43,6 +43,8 @@ where cover is null; create table comment ( id int(10) PRIMARY KEY AUTO_INCREMENT, + nickname varchar(20) null, + email varchar(50) null, article_id int(10) not null, content varchar(500) not null, publish_time datetime not null, diff --git a/modules/comment.js b/modules/comment.js index 14721ad..5a6ac97 100644 --- a/modules/comment.js +++ b/modules/comment.js @@ -6,7 +6,8 @@ const router = require('express').Router(); router.all('/web/query', async (req, res) => { let id = req.query['id']; // 获取要查询文章的编号 if (!id || id < 1) { - res.send({ status: false, message: "参数不对" }) + // 参数不正确 直接返回空数组 + res.send([]) } else { const list = await db.query('select * from comment where article_id =?', [id]); res.send(list) diff --git a/public/detail.html b/public/detail.html index 35ff3f0..403e420 100644 --- a/public/detail.html +++ b/public/detail.html @@ -36,14 +36,16 @@

所有评论

+
- +
- 评论 + 评论
+
{{c.content}}
@@ -78,7 +80,7 @@ el: '#detail', // 设置挂载对象 data() { return { - xxx:'', + xxx: '', isError: false, a: { "id": 0, @@ -92,20 +94,20 @@ "comment_count": 0, "status": 1 }, - // 所有的评论列表 + // 所有评论的列表 commentList: [] } }, async created() { - const params = qs.parse(location.search); + const params = qs.parse(location.search); // 解析查询参数 if (!params.id) { this.setTitle() this.isError = true; return; } - const id = this.a.id = params.id; - await request('./api/article/web/update', { id }) - const articleList = await request('./api/article/web/detail', { id }); + const id = this.a.id = params.id; // 获取并保存文章编号 + await request('./api/article/web/update', { id }) // 更新阅读数量 + const articleList = await request('./api/article/web/detail', { id }); // 查询详情 if (articleList.length != 1) { this.isError = true; this.setTitle() @@ -113,14 +115,14 @@ } this.a = articleList[0]; this.setTitle() - + // 加载评论 this.loadCommentList() }, methods: { async loadCommentList() { const id = this.a.id; - const list = await request('./api/comment/web/query', { id }) + const list = await request('./api/comment/web/query', { id }) // 获取所有的评论列表 this.commentList = list; }, back() {