鍍金池/ 問(wèn)答/HTML/ express調(diào)用next();

express調(diào)用next();

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

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

我應(yīng)該如何獲取上一個(gè)方法里的a1變量;

回答
編輯回答
喜歡你
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)
})

等等方法

2017年8月17日 13:16