MrR*_*ot9 2 javascript dom reactjs react-component
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
export default class Game extends Component {
constructor(props) {
super(props);
this.myRef = React.createRef();
this.check = this.check.bind(this);
}
drawBackground() {
console.log("worked");
}
check () {
this.myRef.current.innerHTML = "Testing";
{this.drawBackground()}
}
render() {
return (
<div>
<h1 ref={this.myRef} id="foo">bar</h1>
{this.check()}
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
我需要访问函数中的text内部标签,但收到此错误 Reactjs: Uncaught TypeError: Cannot set property 'innerHTML' of null。我按照文档进行操作。我错过了什么吗?h1check
| 归档时间: |
|
| 查看次数: |
10276 次 |
| 最近记录: |