【发布时间】:2021-10-05 23:50:04
【问题描述】:
我的代码正确返回了对象,但是当我尝试从中获取值时,它返回未定义。确切的问题是什么?
const Notification = require('../../../models/Notification');
module.exports = function onRouterload() {
return {
allRouter: async (req, res, next) => {
// for the admin layout
req.app.locals.layout = 'admin';
// load notification
async function notification() {
try {
const result = Notification.findAll({ where: { status: 'unread' } });
const data = await result;
return data;
} catch (error) {
console.log(error);
}
}
const notificationInfo = await notification();
// return undefined
console.log(notificationInfo.status);
res.locals.notification = notificationInfo;
next();
},
};
};
【问题讨论】:
标签: node.js express async-await middleware