[英]ReactJs unable to find Ref
我的目標:找到標簽的引用並為其着色。 使用的代碼:
colorizeLabel(){
ReactDOM.findDOMNode(this.refs.amountLabel).color('#ffffff');
}
<label itemRef="amountLabel">Choose Amount:</label>
產生: Uncaught TypeError: Cannot read property 'color' of null
似乎無法找到參考。 我想念什么嗎?
您需要在元素中指定ref
<label ref="amountLabel">Choose Amount:</label>
但是建議如下使用ref
<label ref={(ref) => this.myLabel = ref} />
您可以訪問標簽為this.myLabel
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.