如何在单击事件后更改会话值,以便页面刷新不会重置 Meteor 上的会话 [英] How to change a session value after a click event, so that a page refresh does not reset the session on Meteor

查看:25
本文介绍了如何在单击事件后更改会话值,以便页面刷新不会重置 Meteor 上的会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常接近让我的应用程序按照我想要的方式运行,但是我遇到了一个小问题.在单击事件和用户重新加载页面后,我似乎无法让 Session.set 保持不变.我基本上是在尝试为查看酒类供应商网站建立一个年龄门.

I am very close to having my app perform as I want, however there is one little issue I am having. I cant seem to get the Session.set to stay after a click event and the user reloads the page. I am basically trying to build a age gate for viewing a alcohol vendors site.

您可以在此处查看该站点,当您单击该链接时它会隐藏地图,但是当您刷新它时回来了,我希望它在初始点击和刷新后隐藏地图,但需要初始点击.

You can view the site here, when you click the link it hides the map, but when you refresh it comes back, I want it to hide the map after the initial click and after refresh, but the initial click is needed.

你可以在下面查看我的javaScript

You can view my javaScript below

Template.homePage.helpers({
   // because the Session variable will most probably be undefined the first time
   data: function(){

         return !Session.get("enter");

   }
});

Template.homePage.events({
  'click a' : function(){
    alert("removeMap");
    Session.set("enter", false);
  }
});


Template.homePage.rendered = function(){
  Session.set("enter", true);
}

**

JS 更新

**

Template.homePage.helpers({
   // because the Session variable will most probably be undefined the first time
   data: function(){

         return !Session.get("enter");

   }
});

Template.homePage.events({
  'click a' : function(){
    alert("removeMap");
    Session.setPersistent("enter", false);
    console.log(Session.get("enter"));
  }
});



Meteor.startup(function () {
    Session.setTemp("enter", true);
    console.log(Session.get("enter"));
});

和我的模板

<template name="homePage">



{{#if data}}

{{> postsList}}

{{ else }}

<h1>Choose a Province:</h1>

{{> map}}

<a href="#">Click Me</a>

{{/if}}



</template>

推荐答案

你问的已经是此处此处.

此外,如果您希望会话持久,您可以使用这个包

Also, you can use this package if you want your session to be persistent

这篇关于如何在单击事件后更改会话值,以便页面刷新不会重置 Meteor 上的会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆