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

网站建设 6万元惠州市网站建设

网站建设 6万元,惠州市网站建设,沧州网站设计多少钱,网页设计与制作实验报告总结react react-redux学习记录1.原理2.怎么用呢2.1 容器组件2.2UI组件2.3 App.jsx3.简化3.1简写mapDispatch3.2 Provider组件的使用3.3整合UI组件和容器组件1.原理 UI组件:不能使用任何redux的api#xff0c;只负责页面的呈现、交互等。 容器组件#xff1a;负责和redux通信只负责页面的呈现、交互等。 容器组件负责和redux通信将结果交给UI组件。看得出来容器组件很重要的它连接着ui组件和redux 2.怎么用呢 文件目录结构 2.1 容器组件 import CountUI from ../../components/Count;//引入action import {createIncrementAction,createSubtractionAction,createIncrementAsyncAction } from ../../redux/count_action//connect的第一个第一个参数主要可传两个参数相当于将store中的状态和操作状态传递给UI组件 import { connect } from react-redux;/* 1.mapStateToProps函数返回的是一个对象2.返回的对象中的key就作为传递给UI组件props的key,value就作为传递给UI组件props的value3.mapStateToProps用于传递状态 */ function mapStateToProps(state){return {count:state} }/* 1.mapDispatchToProps函数返回的是一个对象2.返回的对象中的key就作为传递给UI组件props的key,value就作为传递给UI组件props的value3.mapDispatchToProps用于传递操作状态的方法 */ function mapDispatchToProps(dispatch){return {jia:number dispatch(createIncrementAction(number)),jian:number dispatch(createSubtractionAction(number)),jiaAsync:(number,time) dispatch(createIncrementAsyncAction(number,time)),} } //使用connect()()创建并暴露一个Count的容器组件 export default connect(mapStateToProps,mapDispatchToProps)(CountUI) 2.2UI组件 import React, { Component } from react; import store from ../../redux/store;export default class Count extends Component {state { carName: 奔驰c63 };componentDidMount() {store.subscribe(() {this.setState({});});}//加法increment () {const { value } this.selectNumber;this.props.jia(value*1)};//减法decrement () {const { value } this.selectNumber;this.props.jian(value*1,500)};//奇数再加incrementIfOdd () {const { value } this.selectNumber;if (this.props.count % 2 ! 0) {this.props.jia(value*1)}};//异步加incrementAsync () {const { value } this.selectNumber;this.props.jiaAsync(value*1,500)};render() {console.log(UI组件接收到的props是,this.props);return (divh1当前求和为{this.props.count}/h1select ref{(c) (this.selectNumber c)}option value11/optionoption value22/optionoption value33/option/selectnbsp;button onClick{this.increment}/buttonnbsp;button onClick{this.decrement}-/buttonnbsp;button onClick{this.incrementIfOdd}当前求和为奇数再加/buttonnbsp;button onClick{this.incrementAsync}异步加/buttonnbsp;/div);} } 2.3 App.jsx import React, { Component } from react import Count from ./containers/Count import store from ./redux/storeexport default class App extends Component {render() {return (divCount store{store}//div)} } 3.简化 3.1简写mapDispatch export default connect(mapStateToProps, {//和之前的箭头函数都是返回的一个action对象,react-redux优化了自动分发dispatchjia: createIncrementAction,jian: createSubtractionAction,jiaAsync: createIncrementAsyncAction, })(CountUI);3.2 Provider组件的使用 不使用react-redux的话需要在在index.js写上对redux的监听 //这是react18.0之前的版本写法 store.subscrible(() { ReactDOM.render(App/,document.getElementById(root)) })使用react-redux的话不需要监听的了而且在App.jsx中: 如果有很多的容器组件那就需要写很多重复的store{store},优化是当前页面 然后再index.js中使用Provider组件 3.3整合UI组件和容器组件 直接将UI组件和容器组件整合成一个 import React, { Component } from react;//引入action import {createIncrementAction,createSubtractionAction,createIncrementAsyncAction, } from ../../redux/count_action;//connect的第一个第一个参数主要可传两个参数相当于将store中的状态和操作状态传递给UI组件 import { connect } from react-redux;export class Count extends Component {state { carName: 奔驰c63 };//加法increment () {const { value } this.selectNumber;this.props.jia(value*1)};//减法decrement () {const { value } this.selectNumber;this.props.jian(value*1,500)};//奇数再加incrementIfOdd () {const { value } this.selectNumber;if (this.props.count % 2 ! 0) {this.props.jia(value*1)}};//异步加incrementAsync () {const { value } this.selectNumber;this.props.jiaAsync(value*1,500)};render() {console.log(UI组件接收到的props是,this.props);return (divh1当前求和为{this.props.count}/h1select ref{(c) (this.selectNumber c)}option value11/optionoption value22/optionoption value33/option/selectnbsp;button onClick{this.increment}/buttonnbsp;button onClick{this.decrement}-/buttonnbsp;button onClick{this.incrementIfOdd}当前求和为奇数再加/buttonnbsp;button onClick{this.incrementAsync}异步加/buttonnbsp;/div);} }/* 1.mapStateToProps函数返回的是一个对象2.返回的对象中的key就作为传递给UI组件props的key,value就作为传递给UI组件props的value3.mapStateToProps用于传递状态 */ function mapStateToProps(state) {return { count: state }; }/* 1.mapDispatchToProps函数返回的是一个对象2.返回的对象中的key就作为传递给UI组件props的key,value就作为传递给UI组件props的value3.mapDispatchToProps用于传递操作状态的方法 */ // function mapDispatchToProps(dispatch){ // return { // jia:createIncrementAction, // jian:createSubtractionAction, // jiaAsync:createIncrementAsyncAction, // } // }//使用connect()()创建并暴露一个Count的容器组件 export default connect(mapStateToProps, {//和之前的箭头函数都是返回的一个action对象,react-redux优化了自动分发dispatchjia: createIncrementAction,jian: createSubtractionAction,jiaAsync: createIncrementAsyncAction, })(Count);
http://www.eeditor.cn/news/118817/

相关文章:

  • 专业创建网站做网站用的主机
  • 如何将自己做的网站放到网上去广州市网站建站
  • 广东省网站备案查询铁岭网站建设公司
  • 网站建设管理与维护免费ppt模板下载第一ppt
  • 可以做商城网站的公司海外跨境电商平台排行榜前十名
  • 服装做外贸的网站建设保定市城市规划建设局网站
  • 网站建设合同包含什么企业申请域名
  • 大型电子商务网站建设公司陕西公司网站建设
  • 青岛关键词网站排名一个网站建设花了10万元
  • 网站开发职业资格证书wordpress搜索框删除
  • 网站页面布局优化广州seo顾问
  • 深圳做棋牌网站建设多少钱深圳网络推广哪家公司好
  • 设计成功一个电子商务网站吴江微信网站制作
  • 广州企业如何建网站华为云企业邮箱登录入口
  • 个人可以做网站么莱芜在线话题凤城高中
  • 给个网站做导航违法吗校园网二级网站的建设
  • 设计接单网站大全宁波seo哪家最便宜
  • 济南美赞网站建设公司电工培训
  • 网站建设公司哪里找做试管的网站
  • 如何申请免费的网站空间做业务一般要注册哪些网站
  • 网站电线电话图怎么做什么是ui设计效果图
  • 装饰设计乙级资质承接范围合肥seo整站优化
  • 泳衣服饰东莞网站建设博物馆网站建设
  • dedecms建手机网站个人网页制作实验报告
  • 建筑网站、导航栏网站模板特效
  • 网站开发语言开发厨师培训机构 厨师短期培训班
  • xml网站地图每天更新做网站淘汰了
  • 石家庄网站建设咨询薇在工行网站上如何做现金理财
  • 网站开发需求用什么软件app开发公司费用
  • 邯郸营销网站建设营销培训学院