4 回答

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊
// Global.js
var Global = {};
module.exports = Global;
// 調(diào)用的頁(yè)面
let Global = require('./Global');
Global.userToken = 'token';

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊
例如點(diǎn)擊按鈕就新增一個(gè)子組件,同時(shí)需要使用ref引用子組件,我像下面這樣把ref寫(xiě)在handleClick里面時(shí),因?yàn)椴辉趓ender里面,會(huì)報(bào)錯(cuò):addComponentAsRefTo(...): Only a ReactOwner can have refs.
var Father = React.createClass({
getInitalState:function(){
return {children:[]}
},
handleClick:function(){
var childrenTemp = this.state.children
this.setState{children:childrenTemp.push(<Child ref="childRef">)}
},
render:function(){
return (
<div>{this.state.children}</div>
)
}
})
- 4 回答
- 0 關(guān)注
- 888 瀏覽
添加回答
舉報(bào)