随笔分类 -  React

摘要:npx create-react-app my-app cd my-app npm start 添加路由库 react-router-dom npm i react-router-dom package.js name:项目名称 version:项目版号 private:项目是否开源 depende 阅读全文 »
posted @ 2022-11-18 17:28 Cherishe 阅读(20) 评论(0) 推荐(0) 编辑
摘要:第零步:导入 import React,{useState,useEffect} from "react" 第一步: 创建函数组件: export default function Banner(){ 第二步: 改变状态: const [n,setN] = useState(0)//改变数值 con 阅读全文 »
posted @ 2022-11-18 16:55 Cherishe 阅读(57) 评论(0) 推荐(0) 编辑
摘要:// 导入 import React,{} from "react" //使用:基本结构 export default class Banner extends React.Component{ //状态: constructor(){ super(); this.state={ //写数据 } } 阅读全文 »
posted @ 2022-11-18 13:44 Cherishe 阅读(42) 评论(0) 推荐(1) 编辑
摘要:Effect Hook: 函数组件执行副作用操作 函数组件+hook import React,{useEffect,useState} from "react" export default function Hook(){ //状态:(声明) const [count,setCount] = u 阅读全文 »
posted @ 2022-11-18 12:43 Cherishe 阅读(13) 评论(0) 推荐(0) 编辑
摘要:hook: 特殊的函数 hook作用: 钩入react的特性 useState: 函数组件添加state的hook hook的声明: 类组件: default export class Hook extends react.Component{ //在这里写状态: constructor(){ su 阅读全文 »
posted @ 2022-11-18 12:16 Cherishe 阅读(110) 评论(0) 推荐(0) 编辑
摘要:Hook是React 16.8的新增特性,它可以在不编写类组件的情况下使用state以及其他React特性 Hook和函数组件: React的函数组件处理是这样的 const Demo = (props)=>{ // 可以在这使用 Hook ... return <div>Hook</div> } 阅读全文 »
posted @ 2022-11-17 21:48 Cherishe 阅读(96) 评论(0) 推荐(0) 编辑
摘要:使用React构建单页面应用,要想实现页面间的跳转,首先想到的就是使用路由 下载: npm install react-router-dom //或者 yarn add react-router-dom 路由组件: BrowserRouter BrowserRouter: 为一个容器,用来放Rout 阅读全文 »
posted @ 2022-11-17 20:13 Cherishe 阅读(26) 评论(0) 推荐(0) 编辑
摘要:export default class App extends Component{ // 状态: constructor(){ super()//父级构造函数调用 this.state={ title:'zhaoxing', id:'1' } } // 渲染: render(){ return 阅读全文 »
posted @ 2022-11-17 19:21 Cherishe 阅读(18) 评论(0) 推荐(0) 编辑
摘要:组件: 可以编写react元素 虚拟DOM: react元素 真实的DOM: 可以展示 React里很重要的: 组件 组件目的: 复用 组件作用: 代码分隔 组件在React里有两种定义的方式: 第一种: 定义组件: 函数(JS函数) 函数组件:(不负责状态,只负责渲染) 功能组件 无状态组件 函数 阅读全文 »
posted @ 2022-11-17 14:53 Cherishe 阅读(28) 评论(0) 推荐(0) 编辑
摘要:第一个加载的组件就是APP: <APP/> 当前咱们指定的DOM就是root: ReactDOM.createRoot(document.getElementById('root')); root在那个地方: react-app/public/index.html <div id="root"></ 阅读全文 »
posted @ 2022-11-17 13:41 Cherishe 阅读(16) 评论(0) 推荐(0) 编辑
摘要:node环境>=14.0.0 npm环境>=5.6 安装create-react-app:npm i -g create-react-app (cnpm/yarn) 创建项目:create-react-app react-project(项目名称) 进入项目根目录:cd react-project 阅读全文 »
posted @ 2022-11-17 12:43 Cherishe 阅读(77) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示