[英]How can I set and get cookies (server side) in Meteor?
如何在 Meteor 中设置和获取 cookie(服务器端)?
Meteor does not currently have a supported way to use cookies on the server. Meteor 目前不支持在服务器上使用 cookie 的方式。
You can use cookies on the client, though.不过,您可以在客户端上使用 cookie。 Here's a snippet to show a splash screen the first time the user visits a page:
这是用户第一次访问页面时显示启动画面的片段:
Meteor.startup(function () {
if (!document.cookie.match("splash="))
$('body').append(Meteor.ui.render(Template.splash));
});
Template.splash.events = {
'click .submit': function () {
document.cookie = "splash=ack;expires=Sat, 23 Mar 2013 00:00:0 GMT";
$('#splash_outer').remove();
}
};
You could use a similar approach and set the cookies in client side code, then send the results to the server in a method call.您可以使用类似的方法并在客户端代码中设置 cookie,然后在方法调用中将结果发送到服务器。
It looks like we got a solution: ostrio/cookies which work both on the server side and on the client side: https://atmospherejs.com/ostrio/cookies看起来我们有一个解决方案: ostrio/cookies 在服务器端和客户端都工作: https ://atmospherejs.com/ostrio/cookies
import { Cookies } from 'meteor/ostrio:cookies';
const cookies = new Cookies();
const oldValue = cookies.get("key");
cookies.set("key", "newValue");
2014 年 4 月更新:您现在可以使用meteor-user-session 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.