我尝试使用服务器端方法来设置会话变量。
Meteor.methods({
'countvisit':function(){
var count=mydict;
count=count+1;
console.log("another visit come. Totally "+ count.toString()+" view the site");
mydict=count;
Session.set("globalcount", mydict);
}
});
Session.set上发生错误,我发现无法在服务器端获取会话。错误是:
I20160224-11:34:38.773(11)? another visit come. Totally 1 view the site
I20160224-11:34:38.774(11)? Exception while invoking method 'countvisit' ReferenceError: Session is not defined
I20160224-11:34:38.774(11)? at [object Object].Meteor.methods.countvisit (server/startup.js:12:7)
I20160224-11:34:38.774(11)? at maybeAuditArgumentChecks (livedata_server.js:1698:12)
I20160224-11:34:38.774(11)? at livedata_server.js:708:19
I20160224-11:34:38.774(11)? at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20160224-11:34:38.774(11)? at livedata_server.js:706:40
I20160224-11:34:38.775(11)? at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20160224-11:34:38.775(11)? at livedata_server.js:704:46
I20160224-11:34:38.775(11)? at tryCallTwo (C:\Users\sheng\AppData\Local\.meteor\packages\promise\0.5.1\npm\node_modules\meteor-promise\node_modules\promise\lib\core.js:45:5)
I20160224-11:34:38.775(11)? at doResolve (C:\Users\sheng\AppData\Local\.meteor\packages\promise\0.5.1\npm\node_modules\meteor-promise\node_modules\promise\lib\core.js:171:13)
I20160224-11:34:38.775(11)? at new Promise (C:\Users\sheng\AppData\Local\.meteor\packages\promise\0.5.1\npm\node_modules\meteor-promise\node_modules\promise\lib\core.js:65:3)
如何在服务器上的Meteor.methods()中设置会话变量?
答案 0 :(得分:1)
看起来您正在客户端和服务器上记录页面视图。最好的方法是将其保存到mongo并将其发布回客户端