不能 console.log(req.flash("error")) 和同时呈现消息
Can't console.log(req.flash("error")) and render message at the same time
在 get
部分,我对 console.log() 进行了评论。因此,我在屏幕上收到了相应的消息。但是如果我取消注释它,我会在控制台中收到这样的消息 [message]
但没有消息输出到屏幕。这是为什么?我可以在路由处理程序中没有 2 req.flash('error')
吗?
app.get("/login", function(req, res){
// console.log(req.flash("error"))
res.render('login', { message: req.flash('error') });
})
app.post("/login", function(req, res, next){
console.log("posted")
passport.authenticate("local",{
successRedirect : "/users/" + req.body.username,
failureRedirect : "/login",
failureFlash : true
})(req, res, next)
} )
我正在使用 var flash = require("connect-flash");
由于 connect-flash
包状态 (link),消息在使用后被清除,所以当您控制台记录一个(并使用它)时,它被清除并且当您在 [=18 中再次调用它时=] 它已经是空的了。
编辑: 如果你想多次使用一个 flash 消息,那么一次也许可以将它存储在某个局部变量中,然后 console.log 它并在中使用响应,但这只是一个猜测。我现在没有设置环境来检查它。
在 get
部分,我对 console.log() 进行了评论。因此,我在屏幕上收到了相应的消息。但是如果我取消注释它,我会在控制台中收到这样的消息 [message]
但没有消息输出到屏幕。这是为什么?我可以在路由处理程序中没有 2 req.flash('error')
吗?
app.get("/login", function(req, res){
// console.log(req.flash("error"))
res.render('login', { message: req.flash('error') });
})
app.post("/login", function(req, res, next){
console.log("posted")
passport.authenticate("local",{
successRedirect : "/users/" + req.body.username,
failureRedirect : "/login",
failureFlash : true
})(req, res, next)
} )
我正在使用 var flash = require("connect-flash");
由于 connect-flash
包状态 (link),消息在使用后被清除,所以当您控制台记录一个(并使用它)时,它被清除并且当您在 [=18 中再次调用它时=] 它已经是空的了。
编辑: 如果你想多次使用一个 flash 消息,那么一次也许可以将它存储在某个局部变量中,然后 console.log 它并在中使用响应,但这只是一个猜测。我现在没有设置环境来检查它。