我有一个班级:
deploy:
steps:
- install-packages:
packages: git ssh-client
- leipert/git-push:
gh_oauth: $GIT_AUTH
repo: gh-username/repo-name
branch: gh-pages
basedir: your-created-folder
我希望能够访问在课程顶部定义的export default class Home extends React.Component {
static store = createStore();
constructor() {
super();
// This doesn't work
console.log(this.store);
}
}
变量但是我不确定如何,我假设它是使用store
但它是未定义。
答案 0 :(得分:0)
所以基本上你想在所有类实例之间共享变量?尝试将其传递给构造函数。像这样:
class Home extends React.Component {
constructor(props, context) {
super(props, context);
this.store = props.store;
console.log(this.store);
}
}
你的初始化函数:
function init() {
var props = {
store: createStore()
};
ReactDOM.render(<Home {...props} />, document.getElementById('home1'));
ReactDOM.render(<Home {...props} />, document.getElementById('home2'));
ReactDOM.render(<Home {...props} />, document.getElementById('home3'));
}
和html:
<div id="home1"></div>
<div id="home2"></div>
<div id="home3"></div>