我尝试使用这种方法,但名为 clientIpAddress 的变量的值未定义。
Meteor.methods({
getClientIpAddress: function () {
return this.connection.clientAddress;
}
});
Template.home.helpers({
starsAlreadyReceivedFromIpAddress: function () {
var clientIpAddress;
Meteor.call("getClientIpAddress", function(err, ipAddress) {
clientIpAddress = ipAddress;
});
console.log(clientIpAddress);
....
}
});
如果有人可以帮助我,我将不胜感激。
最佳答案
查看用户状态
包。 https://github.com/mizzao/meteor-user-status
这将为您提供Meteor.user().status.lastLogin.ipAddr
,然后您可以在助手中使用它(首先确保该字段已发布)。
关于Meteor - 如何在 Helper 中获取当前访问者的 IP 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28511314/