Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Error handling 错误登录处理流星_Error Handling_Meteor - Fatal编程技术网

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);
    }
});