Node.js 如何在节点应用程序中使用materialize toast
我有一个node/express应用程序。在前端,我使用的是MaterializeCSS,我想在用户注销时使用它的toast功能 以下是我的注销路径代码:Node.js 如何在节点应用程序中使用materialize toast,node.js,express,materialize,express-handlebars,Node.js,Express,Materialize,Express Handlebars,我有一个node/express应用程序。在前端,我使用的是MaterializeCSS,我想在用户注销时使用它的toast功能 以下是我的注销路径代码: // logout user router.get('/logout', (req, res) => { req.logout(); req.flash('success_msg', 'You are logged out'); res.redirect('/'); }); 当我的用户注销时,我希望使用如下内容
// logout user
router.get('/logout', (req, res) => {
req.logout();
req.flash('success_msg', 'You are logged out');
res.redirect('/');
});
当我的用户注销时,我希望使用如下内容:
M.toast({html: 'I am a toast!'})
我有一个名为_msg.handlebar的部分,我在其中定义了错误和成功消息的部分,这些消息由我的server.js中的全局变量捕获:
{{#if success_msg}}
<div class="alert alert-success">{{success_msg}}</div>
{{/if}} {{#if error_msg}}
<div class="alert alert-danger">{{error_msg}}</div>
{{/if}} {{#if error}}
<div class="alert alert-danger">{{error}}</div>
{{/if}}
因此,我不想显示文本或警报,而是想使用MaterializeCSS toast
请告知 我修改了我的_msg.把手如下:
{{#if success_msg}}
<body onload="M.toast({html: '{{success_msg}}'})">
</body>
{{/if}} {{#if error_msg}}
<body onload="M.toast({html: '{{error_msg}}'})">
</body>
{{/if}} {{#if error}}
<body onload="M.toast({html: '{{error}}'})">
</body>
{{/if}}
{{{#如果成功{u msg}
{{/if}}{{{#if error_msg}}
{{/if}}{{{#if error}}
{{/if}
到目前为止工作得很好,但如果有更好的建议,请提供建议。非常感谢。您还可以通过示例
#toast container{top:10%!important;right:50%!important;}
{{#if success_msg}}
<body onload="M.toast({html: '{{success_msg}}'})">
</body>
{{/if}} {{#if error_msg}}
<body onload="M.toast({html: '{{error_msg}}'})">
</body>
{{/if}} {{#if error}}
<body onload="M.toast({html: '{{error}}'})">
</body>
{{/if}}