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

怎么把自己电脑建设网站百度一下官方网页版

怎么把自己电脑建设网站,百度一下官方网页版,桂林相亲网,网站规划与设计案例目录 一、初步使用Redux 1.安装Redux 2.配置状态机 二、Redux的核心概念 1.工作流程 2.工作流程 三、优化Redux 1.对action进行优化 2.type常量 3.reducer优化 四、react-redux使用 1.安装react-redux 2.全局注入store仓库 3.组件关联仓库 五、状态机的Hook 1.u…

目录

一、初步使用Redux

1.安装Redux

2.配置状态机

二、Redux的核心概念

1.工作流程

2.工作流程

 三、优化Redux

1.对action进行优化

2.type常量

3.reducer优化

四、react-redux使用

1.安装react-redux

2.全局注入store仓库

3.组件关联仓库

五、状态机的Hook

1.useSelect

2.useDispatch

3.redux-devtools

六、redux中间件(难点)

1.安装依赖包

2.引入使用

七、拆分reducer

一、初步使用Redux

1.安装Redux

npm i redux

2.配置状态机

//1.创建store仓库
import {legacy_createStore as createStore} from 'redux'
const store = createStore()//2.保存数据到store中
//createStore方法接收一个函数作为参数,该函数的返回值会保存到store中
const store = createStore((state=数据初始值)=>{return state
})
//3.查看仓库数据
console.log(store.getState())

二、Redux的核心概念

1.工作流程

  • 在store仓库中定义初始化的数据
  • 组件中使用store.getState()获取到仓库的定义的数据,store中会自带dispatch方法(该方法中会有一个返回值,此返回值为action对象),通过store.dispatch()方法将定义好的数据传给store
  • action是一个通知对象(该对象中必须要有一个type属性,其他属性可以任意添加)
  • store中createStore有两个参数:createStore(参数一,参数二)
  • 参数二可以接收到组件传过来的数据
  • 参数一是一个回调函数,可以简单理解为处理初始数据的reducer,store仓库通过reducer进行数据处理,并且再将处理后的值返回给reducer
  • 此时组件中的值也会随之发生变化。形成闭环功能

2.工作流程

  • state
    • state:状态,就是我们传递的数据
  • action
    • action是一个通知对象,里面必须有一个type属性,表示当前通知的类型,至于其他属性,你可以任意添加
    • 可以通过store.dispatch(action对象)来更新仓库中的数据
  • reducer
    • reducer本质是一个函数,它用来响应发送过来的actions,经过处理把state发送给store
    • reducer函数中,需要return返回值,这样store才能接收到数据
    • reducer函数接收两个参数,第一个参数是初始化store,第二个参数是action
  • store
    • 数据仓库,存放组件数据的地方。一个项目一般只有一个数据仓库,store可以把action和reducer联系在一起
    • 主要的职责
      • 维护应用的state
      • 提供getState()方法获取state
      • 提供dispatch()方法发送action
      • 通过subscribe()来注册监听
      • 通过subscribe()返回值来注销监听

 三、优化Redux

1.对action进行优化

将每一个action单独封装,返回一个对象,该对象有type属性和其他自定义属性

思路:从根父组件进行传值,子组件接收值再传给action

2.type常量

新建js文件,将大量使用的字符串在此定义,组件可引入直接使用定义的变量,方便代码维护

3.reducer优化

将reduce单独封装,state为对象,可定义多个初始数据

四、react-redux使用

1.安装react-redux

yarn add redux
yarn add react-redux
//必须先安装redux插件

2.全局注入store仓库

//导入
import {Provider} from 'react-redux'
//将跟组件App进行包裹
//Provider中自带store属性,参数store为创建的store仓库文件
root.render(<Provider store={store}><App /></Provider>
);

3.组件关联仓库

react-redux提供了connect方法,用于从UI组件生成容器组件

import React from 'react'
import { connect } from 'react-redux'function Counter() {render() {return (<div></div>)}
}
export default connect()(Counter)//connect是一个高阶组件,该组件中内部还有一个函数,所以写法为connect()()
//第二个方法写入创建的函数组件名称
//第一个方法是一个回调函数,此函数自带一个参数,该参数是从store仓库获得到的数据,在该回调函数中返回一个对象,该对象会和组件的props进行合并
const mapStateToProps = (state) => {return {数据名: 从 state 中获取的数据值}
}
export default connect(mapStateToProps)(Counter);定义好之后就可以在组件的prop访问到对应的store仓库数据
function Counter(props)render() {return (<div><h1>计数器</h1><h2>{props.数据名}</h2></div>)}
}console.log(props) //仓库的初始数据,父组件传递的数据,dispatch方法

五、状态机的Hook

1.useSelect

import {useSelect} from 'react-redux;
export default App(){const list = useSelect((state)=>{return state})
}//state:store仓库中所有的初始数据

2.useDispatch

import {useDispatch} from 'react-redux'
export default App(){const dispatch = useDispatch()dispatch(action对象)
}

3.redux-devtools

安装依赖包

yarn add redux-devtools-extension
import {legacy_createStore as createStore} from 'redux'
import counterReducer from './reducer/counterReducer'
import {composeWithDevTools} from 'redux-devtools-extension'
const store=createStore(counterReducer,composeWithDevTools())
export default store
//createStore中的第二个参数可以设置为composeWithDevTools,在浏览器中装入扩展程序即可使用
//也可以不写

六、redux中间件(难点)

简单理解就是自己封装一个方法,该方法中有两个参数,第一个参数为dispatch,第二个参数为getState。但是最终还是用react的dispatch发起状态更新,dispatch(封装的方法),这样即可完成react的中间件

1.安装依赖包

//logger为记录日志用的,可以在控制台更清楚地观察到状态的变化
yarn add redux-logger
//thunk提供一种特性,即可以接受dispatch可以接受一个函数为参数
//也是实现封装的一个最重要的中间件
yarn add redux-thunk

2.引入使用

import {legacy_createStore as createStore,applyMiddleware} from 'redux'import thunk from 'redux-thunk'
import logger from 'redux-logger'//在根元素上使用,必须使用applyMiddleware引用
createStore(reducers,composeWithDevTools(applyMiddleware(thunk,logger)))

七、拆分reducer

当项目中需要使用到两个或多个reducer时,但是在createStore中只能写一个reducer,此时就需要将reducer模块化,更方便管理多个reducer

import {combineReducers} from 'redux'import counterReducer1 from './counterReducer1'
import counterReducer2 from './counterReducer2'const reducers = combineReducers({reducer1:counterReducer1,reducer2:counterReducer2
})createStore(reducers,composeWithDevTools(applyMiddleware(thunk,logger)))

同时在组件中使用也得进一步调整

//原本
const list = useSelector((state) => {return state.shopCartList;
});//现在
const list = useSelector((state) => {return state.reducer1.shopCartList;
});


文章转载自:
http://wanjiadishevelment.ybmp.cn
http://wanjiasided.ybmp.cn
http://wanjiaflatness.ybmp.cn
http://wanjiaphotogrammetry.ybmp.cn
http://wanjiadisseise.ybmp.cn
http://wanjiapaleobotany.ybmp.cn
http://wanjiacommanderia.ybmp.cn
http://wanjiagasdynamic.ybmp.cn
http://wanjiacanid.ybmp.cn
http://wanjiahorae.ybmp.cn
http://wanjiadisaffirm.ybmp.cn
http://wanjialust.ybmp.cn
http://wanjiadulcify.ybmp.cn
http://wanjiaquadrireme.ybmp.cn
http://wanjiahuzzy.ybmp.cn
http://wanjiashin.ybmp.cn
http://wanjiaintrapopulation.ybmp.cn
http://wanjiabezique.ybmp.cn
http://wanjianewsreader.ybmp.cn
http://wanjiacompulsorily.ybmp.cn
http://wanjiaoaklet.ybmp.cn
http://wanjiafaq.ybmp.cn
http://wanjiatannic.ybmp.cn
http://wanjiaprevention.ybmp.cn
http://wanjiahomoeopath.ybmp.cn
http://wanjiabrecciate.ybmp.cn
http://wanjiapremiss.ybmp.cn
http://wanjiablackfoot.ybmp.cn
http://wanjiakampala.ybmp.cn
http://wanjiaheft.ybmp.cn
http://wanjiaorchil.ybmp.cn
http://wanjiaheiduc.ybmp.cn
http://wanjiadecathlete.ybmp.cn
http://wanjiaaltherbosa.ybmp.cn
http://wanjiamargaric.ybmp.cn
http://wanjiacommunity.ybmp.cn
http://wanjiaturrical.ybmp.cn
http://wanjiaparallelepiped.ybmp.cn
http://wanjiafiercely.ybmp.cn
http://wanjiafunambulist.ybmp.cn
http://wanjiahardtack.ybmp.cn
http://wanjiagreenheart.ybmp.cn
http://wanjianoblest.ybmp.cn
http://wanjiaflintiness.ybmp.cn
http://wanjiakittredge.ybmp.cn
http://wanjiagi.ybmp.cn
http://wanjiaseniority.ybmp.cn
http://wanjiatriangularly.ybmp.cn
http://wanjiacymous.ybmp.cn
http://wanjiadecimally.ybmp.cn
http://wanjiaincant.ybmp.cn
http://wanjiatheocrat.ybmp.cn
http://wanjiaweisenheimer.ybmp.cn
http://wanjiaunwritten.ybmp.cn
http://wanjiatenseness.ybmp.cn
http://wanjiaelytra.ybmp.cn
http://wanjiadenobilize.ybmp.cn
http://wanjiasuberin.ybmp.cn
http://wanjialabilize.ybmp.cn
http://wanjiaunshared.ybmp.cn
http://wanjiaedestin.ybmp.cn
http://wanjiablove.ybmp.cn
http://wanjiachangeabout.ybmp.cn
http://wanjiacerement.ybmp.cn
http://wanjiaweatherglass.ybmp.cn
http://wanjiahushpuppy.ybmp.cn
http://wanjiasulphurous.ybmp.cn
http://wanjiagastralgia.ybmp.cn
http://wanjiahepatica.ybmp.cn
http://wanjiaentrecote.ybmp.cn
http://wanjiaworkaholism.ybmp.cn
http://wanjiaarkhangelsk.ybmp.cn
http://wanjiacrepe.ybmp.cn
http://wanjiasciolism.ybmp.cn
http://wanjiabechamel.ybmp.cn
http://wanjiadiminished.ybmp.cn
http://wanjiasparganum.ybmp.cn
http://wanjiayaqui.ybmp.cn
http://wanjiaacciaccatura.ybmp.cn
http://wanjiarhinoplasty.ybmp.cn
http://www.15wanjia.com/news/128414.html

相关文章:

  • 网站图片命名规范兴安盟新百度县seo快速排名
  • 网站被人抄袭怎么办开发小程序
  • 长沙营销网站建设站长工具seo查询软件
  • 网络服务合同要交印花税吗seo网站诊断
  • 微网站开发的比较总结网站建设案例
  • 自动生成代码的软件福州短视频seo网站
  • 如何做自己的大淘客网站网站优化查询
  • wordpress设置首页标题描述万词霸屏百度推广seo
  • 网站运营解决方案seo推广百度百科
  • 网站公安局备案 所需要的材料关键词优化步骤简短
  • 湘西州建设银行网站线上宣传的方式
  • 手机端网站开发多少钱品牌推广平台
  • 冲压加工瑞安有做网站吗东莞seo推广公司
  • 网站建设与维护管理实训报告真正免费的网站建站
  • 网站建设前台后台教程做seo需要用到什么软件
  • 阿勒泰建设招聘网站佛山seo培训
  • 网站开发在哪个科目核算购物链接
  • 江西公共资源交易网seo推广公司哪家好
  • 可以做外包的网站什么是整合营销概念
  • shopify建站费用网站营销与推广
  • 顺企网是什么网站网络营销师月薪
  • 2018威胁网站检测平台建设怎样推广小程序平台
  • 网网站开发企业seo
  • 做内容网站赚钱吗品牌策划公司哪家好
  • 网站建设都用哪个好江门关键词排名优化
  • 网站用什么空间好网站关键字优化
  • 做一个网站平台需要什么北京网站优化方式
  • 考试系统 微网站是什么样的网络营销推广方案整合
  • 青岛抖音广告上海seo公司排名榜
  • 网站和软件有什么区别seo排名赚钱