【发布时间】:2017-04-22 21:19:22
【问题描述】:
这个 Meteor 服务器代码尝试在公共方法“sendEmail”中使用 Meteor.userId(),但有时我会收到错误
Error Meteor.userId 只能在方法调用中调用。使用 this.userId
lib = (function () {
return Object.freeze({
'sendEmail': function(msg){
let userId = Meteor.userId();
//do stuff for this user
},
'otherPublicMethod': function(){
//do other things then use sendEmail
lib.sendEmail(); // <---- Error Meteor.userId can only be invoked in method calls. Use this.userId
}
});
}());
// Now I call sendEmail from any where, or can I?
Meteor.methods({
'sendEmail': (msg) => {
lib.sendEmail(msg); // <---- NO error when this is called
},
});
如何解决?谢谢
【问题讨论】:
-
userId()不允许在Publications内使用,但在Methods内使用没有限制。
标签: meteor