SuccessModel is not a Constructor
来源:5-6 初始化路由
慕慕2933357
2022-07-30
resModel的代码
class BaseModel {
constructor(data, message) {
if(typeof data === 'string' && typeof message === 'string'){
throw new Error("two String params,only one params")
}
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.export ={
SuccessModel,
ErrorModel
}
router/blog的代码
const {getList} = require('../controller/blog')
const {SuccessModel,ErrorModel} = require('../model/resModel')
const handleBlogRouter = (req,res) => {
const method = req.method
if(method === 'GET' && req.path === "/api/blog/list"){
const author = req.query.author || ''
const keyword = req.query.keyword || ''
const listdata = getList(author,keyword)
return new SuccessModel(listdata)
}
if(method === 'GET' && req.path === "/api/blog/detail"){
return{
msg:'获取博客详情接口'
}
}
if(method === 'POST' && req.path === "/api/blog/del"){
return{
msg:'删除博客接口'
}
}
if(method === 'POST' && req.path === "/api/blog/new"){
return{
msg:'新建博客接口'
}
}
if(method === 'POST' && req.path === "/api/blog/update"){
return{
msg:'更新博客接口'
}
}
}
module.exports = handleBlogRouter
controller/blog代码
const getList = (author,keyword) => {
return
[
{
id:1,
title:'标题A',
content:'内容A',
createTime:1659146935340,
author:'zhangsan'
},
{
id:2,
title:'标题A',
content:'内容A',
createTime:1659146947276,
author:'lisi'
}
]
}
module.exports={
getList
}
写回答
2回答
-
这里少了个 s ,低级错误
012022-08-02 -
双越
2022-07-30
报错截图发给我吧,我看下具体哪一行报错了
062022-08-02
相似问题