Error handling 错误登录处理流星
我有这个自定义登录表单Error handling 错误登录处理流星,error-handling,meteor,Error Handling,Meteor,我有这个自定义登录表单 <template name="login"> {{> alert}} <form> <input type="text" name="username" > <input type="password" name="password" > <input type="submit" value="Login" > </form&g
<template name="login">
{{> alert}}
<form>
<input type="text" name="username" >
<input type="password" name="password" >
<input type="submit" value="Login" >
</form>
</template>
<template name="alert">
{{alert}}
</template>
问题是当我触发错误并尝试打开其他页面并返回登录页面时,警报消息仍然存在。只有当我刷新浏览器或成功登录时,警报消息才会消失
如何使用错误处理使警报消息只触发一次是最好的方法。这包括其他表单错误处理
感谢您的光临。您可以在返回视图时清除会话变量,如下所示:
Template.login.rendered = function () {
Session.set('alert', null);
};
您可以在警报上定义超时。如果希望所有警报都具有此行为,请在“app.js”文件中全局定义。我在我的meteor应用程序中得到了这个。您的警报将持续6秒:
Deps.autorun(function() {
if(Session.get('alert')){
setTimeout(function () {
Session.set('alert','');
}, 6000);
}
});
Deps.autorun(function() {
if(Session.get('alert')){
setTimeout(function () {
Session.set('alert','');
}, 6000);
}
});