express调用next();

function a(){
    var a1 = 'Hello World!';
    next();
}

app.get('/b', a, function (req, res) {
  res.send(a1);
});

我应该如何获取上一个方法里的a1变量;

阅读 2.3k
2 个回答
function a(req, res, next) {
    const a1 = 'this is a1'
    //req.a1 = a1
    res.locals.a1 = a1
    next()
}

app.get('/b', a, (req, res) => {
    res.send(res.locals.a1)
})

等等方法

function a(){
    var a1 = 'Hello World!';
    next(a1);
}

app.get('/b', a, function (a1, req, res) {
  res.send(a1);
});
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题