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

有了网站 域名然后么做免费手机网页制作

有了网站 域名然后么做,免费手机网页制作,wordpress菜单跳转页面,什么是网络营销4p策略需求: 左上侧:状态左下侧:棋盘,保证胜利就结束 和 下过来的不能在下右侧:“时光机”,保证可以回顾,索引 语法: 父子之间属性传递(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.15wanjia.com/news/10907.html

相关文章:

  • 聊城做网站的公司渠道百度站长工具抓取诊断
  • 新开神途手游发布网站网站seo属于什么专业
  • 做铜字接单网站关键词排名零芯互联关键词
  • 免费服务器试用网站seo推广seo教程
  • 网站开发中为什么有两个控制层培训机构如何招生营销
  • 中国建筑装饰网唐迪夫百度seo官方网站
  • 个人主页网站html群站优化之链轮模式
  • 东莞兼职招聘网最新招聘手机网站怎么优化
  • 上海企业网站制作百度推广管理
  • 网站建设前期规划方案seo公司推广宣传
  • 网站建设方案及预算搜索引擎优化的主要内容
  • 住房城乡建设部官网哈尔滨网站优化
  • 沧州网络营销推广方案优化公司哪家好
  • 网站开发 盈利seo推广宣传
  • 成都诗和远方网站建设企业网站设计
  • net域名大网站关键词优化推广公司哪家好
  • 武汉网页设计班培训新站seo外包
  • 台州网站公司建站网络推广哪个平台效果最好
  • 陕西西安网站建设公司百度如何购买关键词
  • 如何查询网站已经提交备案seo营销策划
  • dede模板打网站显示栏logo著名营销策划公司
  • 安阳网站制作哪家好北京seo多少钱
  • 用源码怎么做网站什么是软文
  • 苹果软件 做ppt模板下载网站有哪些制作网站的步骤和过程
  • 重庆做学校网站公司东莞百度快速优化排名
  • 上海网站快速优化排名网站制作开发
  • 怎么查询网站开通时间谷歌seo运营
  • wordpress网站特效代刷网站推广链接0元价格
  • 建网站免费吗线上推广的方法
  • 外国优秀设计网站推荐百度竞价关键词优化