Meteor.user() 在 Chrome 中不起作用
Meteor.user() doesn't work in Chrome
我正在尝试 console.log(Meteor.user().profile.group)
:但它会导致以下错误:
Uncaught TypeError: Cannot read property 'profile' of undefined
单独使用 Meteor.user()
returns 未定义。
这是 Mongo 上的用户详细信息:
{
"_id" : "ccZztbFqw2MpgTsjX",
"createdAt" : ISODate("2017-12-12T15:11:23.645Z"),
"services" : {
"password" : {
"bcrypt" : "a$lsYo7wjhA77.8TmNYeMTQ.u3jZzJSiIxsJrMRkjOPINHuLhBOENqm"
}
},
"emails" : [
{
"address" : "111@211.com",
"verified" : false
}
],
"profile" : {
"name" : "11111",
"createdAt" : ISODate("2017-12-12T15:11:23.558Z"),
"updatedAt" : ISODate("2017-12-12T15:11:23.558Z"),
"group" : "user"
}
}
为什么 Meteor.user()
在 Chrome 中不起作用?
注意: Meteor.user().profile.group
使用 Microsoft Edge 浏览器将组打印到控制台
默认情况下,Meteor 不会公开用户集合(为了您自己的利益),如果您想控制公开的内容和不公开的内容,只需为 "userData".[=10= 添加发布功能即可]
可以,但是从服务器下载用户文档需要一段时间。
首次在浏览器中加载应用程序时,Meteor.user() 可以未定义。
您的用例是什么?如果你想在模板中访问当前用户,你可以使用 currentUser
helper:
{{#if currentUser}}
{{currentUser.profile.group}}
{{/if}}
如果您从 Chrome 开发者控制台调用 Meteor.user()
,您还可以看到其中的内容。
我正在尝试 console.log(Meteor.user().profile.group)
:但它会导致以下错误:
Uncaught TypeError: Cannot read property 'profile' of undefined
单独使用 Meteor.user()
returns 未定义。
这是 Mongo 上的用户详细信息:
{
"_id" : "ccZztbFqw2MpgTsjX",
"createdAt" : ISODate("2017-12-12T15:11:23.645Z"),
"services" : {
"password" : {
"bcrypt" : "a$lsYo7wjhA77.8TmNYeMTQ.u3jZzJSiIxsJrMRkjOPINHuLhBOENqm"
}
},
"emails" : [
{
"address" : "111@211.com",
"verified" : false
}
],
"profile" : {
"name" : "11111",
"createdAt" : ISODate("2017-12-12T15:11:23.558Z"),
"updatedAt" : ISODate("2017-12-12T15:11:23.558Z"),
"group" : "user"
}
}
为什么 Meteor.user()
在 Chrome 中不起作用?
注意: Meteor.user().profile.group
使用 Microsoft Edge 浏览器将组打印到控制台
默认情况下,Meteor 不会公开用户集合(为了您自己的利益),如果您想控制公开的内容和不公开的内容,只需为 "userData".[=10= 添加发布功能即可]
可以,但是从服务器下载用户文档需要一段时间。
首次在浏览器中加载应用程序时,Meteor.user() 可以未定义。
您的用例是什么?如果你想在模板中访问当前用户,你可以使用 currentUser
helper:
{{#if currentUser}}
{{currentUser.profile.group}}
{{/if}}
如果您从 Chrome 开发者控制台调用 Meteor.user()
,您还可以看到其中的内容。