当前位置: 首页 > news >正文

c 能和php一起做网站吗免费隐私网站推广

c 能和php一起做网站吗,免费隐私网站推广,郑州专业建站报价,乌鲁木齐企业黄页网需求: 左上侧:状态左下侧:棋盘,保证胜利就结束 和 下过来的不能在下右侧:“时光机”,保证可以回顾,索引 语法: 父子之间属性传递(props)子父组件传递(写法上&…

 

需求:

  • 左上侧:状态
  • 左下侧:棋盘,保证胜利就结束 和 下过来的不能在下
  • 右侧:“时光机”,保证可以回顾,索引

 语法:

  • 父子之间属性传递(props
  • 子父组件传递(写法上!回调函数,若与前者相同会出现无限渲染)
//父组件中声明<Square value={squares[0]} onSquareClick={() => handleClick(0)} />
//子组件接收或发射function Square({ value, onSquareClick }) {return (<button className="square" onClick={onSquareClick}>{value}</button>);
}

Idea 时光机:

  • 不改动原数组,slice()拷贝原数组,[...history,squares]存各个时间数据
  • 若与每一步索引有关,[...history.slice(0, currentMove + 1), nextSquares]
import { useState } from 'react';function Square({ value, onSquareClick }) {return (<button className="square" onClick={onSquareClick}>{value}</button>);
}function Board({ xIsNext, squares, onPlay }) {function handleClick(i) {if (calculateWinner(squares) || squares[i]) {return;}const nextSquares = squares.slice();if (xIsNext) {nextSquares[i] = 'X';} else {nextSquares[i] = 'O';}onPlay(nextSquares);}const winner = calculateWinner(squares);let status;if (winner) {status = 'Winner: ' + winner;} else {status = 'Next player: ' + (xIsNext ? 'X' : 'O');}return (<><div className="status">{status}</div><div className="board-row"><Square value={squares[0]} onSquareClick={() => handleClick(0)} /><Square value={squares[1]} onSquareClick={() => handleClick(1)} /><Square value={squares[2]} onSquareClick={() => handleClick(2)} /></div><div className="board-row"><Square value={squares[3]} onSquareClick={() => handleClick(3)} /><Square value={squares[4]} onSquareClick={() => handleClick(4)} /><Square value={squares[5]} onSquareClick={() => handleClick(5)} /></div><div className="board-row"><Square value={squares[6]} onSquareClick={() => handleClick(6)} /><Square value={squares[7]} onSquareClick={() => handleClick(7)} /><Square value={squares[8]} onSquareClick={() => handleClick(8)} /></div></>);
}export default function Game() {//const [xIsNext, setXIsNext] = useState(true);//初始化为一个[[null,null.......null]],二维数组const [history, setHistory] = useState([Array(9).fill(null)]);const [currentMove, setCurrentMove ]= useState(0);// const currentSquares = history[history.length-1];const currentSquares = history[currentMove];const xIsNext= currentMove % 2 === 0;function handlePlay(nextSquares) {//如果 history 为 [[null,null,null], ["X",null,null]],nextSquares 为 ["X",null,"O"],则新的 [...history, nextSquares] 数组将为 [[null,null,null], ["X",null,null], ["X",null,"O"]]// setHistory([...history, nextSquares]);// setXIsNext(!xIsNext);const nextHistory = [...history.slice(0, currentMove + 1), nextSquares];setHistory(nextHistory);setCurrentMove(nextHistory.length - 1)}const moves=history.map((squares,move)=>{let description;if (move>0){description='Go to move#' +move;}else {description='Go to game start';}return(<li key={move}><button onClick={()=>jumpTo(move)}>{description}</button></li>)})function jumpTo(nextMove){setCurrentMove(nextMove);}return (<div className="game"><div className="game-board"><Board xIsNext={xIsNext} squares={currentSquares} onPlay={handlePlay} /></div><div className="game-info"><ol>{moves}</ol></div></div>);
}function calculateWinner(squares) {const lines = [[0, 1, 2],[3, 4, 5],[6, 7, 8],[0, 3, 6],[1, 4, 7],[2, 5, 8],[0, 4, 8],[2, 4, 6],];for (let i = 0; i < lines.length; i++) {const [a, b, c] = lines[i];if (squares[a] && squares[a] === squares[b] && squares[a] === squares[c]) {return squares[a];}}return null;
}

http://www.dinnco.com/news/52243.html

相关文章:

  • 长春 房地产网站建设百度竞价优化软件
  • 广州做网站 信科网络如何推广网页
  • 四川省城乡建设网站百度网盘私人资源链接
  • 北京做网站公司哪家好企业网站开发公司
  • 怎么删除网站里的死链接长尾关键词网站
  • 天河网站建设集团怎么注册网址
  • 网站备案 拍照软文营销的概念
  • 莱芜找工作网站百度分公司
  • 什么网站做二手货车微博热搜榜排名今日
  • 自己做网站要不要租服务器百度电脑版
  • 网站建设后期维护方案爆款采集推广引流软件
  • 教育行业手机wap网站天津seo优化公司
  • 云平台网站开发无锡谷歌优化
  • 网页代码小游戏seo实战培训机构
  • 怎样做自己的微商网站自助发外链网站
  • 刚做的公司网站搜不到在线注册网站
  • 源代码管理网站优化设计三年级上册答案语文
  • 好的平面设计网站有哪些推广方案
  • wordpress js 版本号官网seo哪家公司好
  • 八年级信息上册如何做网站商丘网络推广公司
  • wordpress主题tint-k晋城网站seo
  • 网站建设流程发布网站和网页制作株洲网站设计外包首选
  • 农业公司网站源码十大互联网平台
  • 香港做网站武汉seo全网营销
  • 网站美工效果图怎么做网站外包
  • 东莞市南华职业技术学校推荐seo关键词优化
  • 对于诈骗网站怎么做网络推广方案书模板
  • 济南做网站的公司seo排名快速
  • 开个小网站要怎么做的seo排名是什么意思
  • 网站手机页面做多大谷歌浏览器怎么下载