带有胡子模板的node.js中的flash消息

时间:2016-07-28 05:42:48

标签: javascript node.js express mustache

我开始使用hackathon starter github repo here构建一个node.js express app但很快意识到我需要改变一些东西。我现在正在使用小胡子,但仍想显示flash消息。看起来{{messages.errors}}包含一些信息,但是当我登录时,显示的是[object,Object]。

如何查看这些对象的内容?

flash.mustache文件如下所示:

<script>
if ("{{messages.errors}}" != ""){
  console.log({{messages()}})
  console.log("error", {{messages()}}); // this line is seen as console.log("error",);
}
</script>

并按照您的预期

将flash添加到app.js
const flash = require('express-flash');
app.use(flash());

并且在路线中闪光按照您的预期处理(例如):

if (!user) {
  req.flash('errors', { msg: 'Account with that email address does not exist.' });
  return res.redirect('/forgot');
}

1 个答案:

答案 0 :(得分:0)

要获取消息,请尝试messages.errors.msg

或者您可以保存此req.flash('errors', 'Account with that email address does not exist.')之类的邮件,然后获取邮件messages.errors