老师,你好,我在这节运行时候报出下面错误
下面是代码:
router/blog.js
const {getList} = require('../controller/blog')
const { SuccessModel, ErrorModel } = require('../model/resModel')
const handleBlogRouter = (req,res)=> {
const method = req.method //GET POST
//获取博客列表
if (method === 'GET' && req.path === '/api/blog/list') {
const author = req.query.author || ''
const keyword = req.query.keyword || ''
const listData = getList(author,keyword)
//listData是请求返回的数据数组,我们还要设置返回的code和message信息,需要利用model进行数据格式的修整
return new SuccessModel(listData)
}
//获取博客详情
if(method === 'POST' && req.path === '/api/blog/detail'){
return {
msg : '这是获取博客详情的接口'
}
}
//新建一篇博客
if(method === 'POST' && req.path === '/api/blog/new'){
return {
msg : '这是新建博客详情的接口'
}
}
//更新一篇博客
if(method === 'POST' && req.path === '/api/blog/update'){
return {
msg : '这是更新博客详情的接口'
}
}
//一篇博客
if(method === 'POST' && req.path === '/api/blog/del'){
return {
msg : '这是删除一篇博客的接口'
}
}
}
module.exports = handleBlogRouter
model/resModel.js
/*
* @Author: yangyang
* @Date: 2019-07-30 08:59:02
* @Last Modified by: yangyang
* @Last Modified time: 2019-07-30 08:59:02
*/
class BaseModel {
constructor(data, message) {
//data是对象类型,message是字符串类型,如果第一个传入的就是字符串类型,第二个没传,要兼容,就把传入的字符串赋给message
if (typeof data === 'string') {
this.message = data
data = null
message = null
}
if (data) {
this.data = data
}
if (message) {
this.message = message
}
}
}
class SuccessModel extends BaseModel {
constructor(data, message) {
super(data, message)
this.errno = 0
}
}
class ErrorModel extends BaseModel {
constructor(data, message) {
super(data, message)
this.errno = -1
}
}
module.exports = {
SuccessModel,
ErrorModel
}
还有项目目录结构:
老师帮忙看下哪里有问题,麻烦老师了