javascript Déclarationdecomponent
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Déclarationdecomponent相关的知识,希望对你有一定的参考价值。
class Board extends React.Component {
constructor(props) {
\!h super(props);
this.state = {
// Initialization of the square values.
// In React, we must use a descendant logical to share data between components.
squares: Array(9).fill(null)
};
}
handleClick(i) {
const squares = this.state.squares.slice();
squares[i] = 'X';
this.setState({squares: squares});
}
renderSquare(i) {
return <Square value={this.state.squares[i]} onClick={() => this.handleClick(i)}/>;
}
render() {
const status = 'Next player: X';
return (
<div>
<div className="status">{status}</div>
<div className="board-row">
{this.renderSquare(0)}
{this.renderSquare(1)}
{this.renderSquare(2)}
</div>
<div className="board-row">
{this.renderSquare(3)}
{this.renderSquare(4)}
{this.renderSquare(5)}
</div>
<div className="board-row">
{this.renderSquare(6)}
{this.renderSquare(7)}
{this.renderSquare(8)}
</div>
</div>
);
}
}
以上是关于javascript Déclarationdecomponent的主要内容,如果未能解决你的问题,请参考以下文章
javascript DécouvertedeNodeJS
javascript DécouverteNodeJs
javascript Déclarationdecomponent
javascript Déclarationdecomponent没有范围
javascript Express 1 - Découverted'express
html Bases de JavaScript 1 - Découvertedulangage