采纳答案成功!
向帮助你的同学说点啥吧!感谢那些助人为乐的人
koa2 中用return await exec(sql).then(result => {return result[0]}) 报错。 修改为 const result = await exec(sql); return result[0]即运行正确
<-- GET /api/user/login?username=zhangsan&password=123
select username,realname from users where username='zhangsan' and password =123
[ RowDataPacket { username: 'zhangsan', realname: '张三' } ]
xxx GET /api/user/login?username=zhangsan&password=123 500 21ms -
server error TypeError: Cannot read property 'username' of undefined
at router.get (E:\gitspace\iview_main\server\routes\login.js:12:11)
at process.internalTickCallback (internal/process/next_tick.js:77:7) { request:
{ method: 'GET',
Cannot read property 'username' of undefined ,找到这一行代码,然后继续往上追踪就是了。例如 username 是哪个变量的?这个变量如何赋值的,为何是 undefined ?顺着这个思路慢慢找。
登录后可查看更多问答,登录/注册
从入门到实战,一站式掌握 Node.js+Express+Koa2
2.3k 16
1.4k 16
1.6k 15
1.4k 13