无法在 React 中访问来自 Meteor 的数据
Unable to access data from Meteor in React
尝试访问根页面时,我得到一个没有布局的空白屏幕。我检查开发人员工具并在 App.jsx
中收到错误
Uncaught TypeError: Cannot read property 'loggedIn' of undefined
这是我的 App 组件:
App = React.createClass({
mixin: [ReactMeteorData],
getMeteorData() {
return {
loggedIn: !!Meteor.user()
};
},
showLayout() {
return (
<div className="container-fluid main-container">
<div className="col-xs-3">
{this.props.nav}
</div>
<div className="col-xs-9">
{this.props.content}
</div>
</div>
)
},
showLogin() {
return (
<div className="row">
<div className="col-xs-12 text-center">
<p>You must be logged in to do that.</p>
</div>
<Login />
</div>
)
},
render() {
return(
<div className="container-fluid main-container">
<div className="row">
{ this.data.loggedIn ? this.showLayout() : this.showLogin() }
</div>
</div>
)
}
});
我不确定是什么问题,我正在学习教程。
你应该有这个:
mixins: [ReactMeteorData],
而不是这个:
mixin: [ReactMeteorData],
(注意's')
尝试访问根页面时,我得到一个没有布局的空白屏幕。我检查开发人员工具并在 App.jsx
中收到错误Uncaught TypeError: Cannot read property 'loggedIn' of undefined
这是我的 App 组件:
App = React.createClass({
mixin: [ReactMeteorData],
getMeteorData() {
return {
loggedIn: !!Meteor.user()
};
},
showLayout() {
return (
<div className="container-fluid main-container">
<div className="col-xs-3">
{this.props.nav}
</div>
<div className="col-xs-9">
{this.props.content}
</div>
</div>
)
},
showLogin() {
return (
<div className="row">
<div className="col-xs-12 text-center">
<p>You must be logged in to do that.</p>
</div>
<Login />
</div>
)
},
render() {
return(
<div className="container-fluid main-container">
<div className="row">
{ this.data.loggedIn ? this.showLayout() : this.showLogin() }
</div>
</div>
)
}
});
我不确定是什么问题,我正在学习教程。
你应该有这个:
mixins: [ReactMeteorData],
而不是这个:
mixin: [ReactMeteorData],
(注意's')