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回答

双越

2022-08-02

这里少了个 s ,低级错误

//img.mukewang.com/szimg/62e8813009f36b9605000268.jpg

0
1
慕慕2933357
非常感谢!
2022-08-02
共1条回复

双越

2022-07-30

报错截图发给我吧,我看下具体哪一行报错了

0
6
慕慕2933357
回复
双越
是undefined
2022-08-02
共6条回复

Node.js+Express+Koa2+Nest.js 开发服务端

从入门到实战,一站式掌握 Node.js+Express+Koa2

4051 学习 · 2006 问题

查看课程