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

网站建设公司公司好建筑工程网络设计

网站建设公司公司好,建筑工程网络设计,成品app直播源码推荐,网页链接提取// 定义redux函数// 第一个参数为状态对象,第二个是修改状态的方向function reducer (state {count:0}, action){// 数据不可变 需要基于原始数据获得当前新数据if(action.type "INCREMENT"){return {count:state.count1}}else if (action.type "…

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

 // 定义redux函数// 第一个参数为状态对象,第二个是修改状态的方向function reducer (state = {count:0}, action){// 数据不可变 需要基于原始数据获得当前新数据if(action.type === "INCREMENT"){return {count:state.count+1}}else if (action.type === "DECREMENT"){return {count:count.type-1}}} // 创建一个store实例使用redux函数const store = creatStore(reducer)// 通过store的实例对象订阅数据变化// 回调函数会在数据变化时候自动执行store.subscribe(()=>{console.log(`数据修改了`,store.getStore())document.getElementById(`count`).innerHTML = store.getStore().count})// 只能使用store实例调用的dispitch函数修改状态const inbtn = document.getElementById(`increment`)inbtn.addEventListener(`click`,()=>{store.dispatch({type:"INCREMENT"})})const debtn = document.getElementById(`decrement`)inbtn.addEventListener(`click`,()=>{store.dispatch({type:"DECREMENT"})})// 使用store实例调用get

在这里插入图片描述
在这里插入图片描述
每次修改需要store实力对象调用dispitch方法输入一个action 对象,其中有状态值属性决定state的修改

插件

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

流程

在这里插入图片描述
counterStore子模块中

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

文件路径

在这里插入图片描述

store/modules/couterStore.js文件

import { createSlice } from "@reduxjs/toolkit"// 定义对象
const counterStore = createSlice({name: 'counter',// 初始化stateinitialState: {count: 5},// 修改状态的方法 同步方法 支持直接修改reducers: {inscrement (state) {state.count++},decrement (state) {state.count--},addToNum (state, action) {state.count = action.payload}}
})// 解构出来actionCreater函数
const { inscrement, decrement, addToNum } = counterStore.actions
// 获取reducer
const reducer = counterStore.reducer// 以按需导出的方式导出actionCreater
export { inscrement, decrement, addToNum }
// 以默认导出的方式导出reducer
export default reducer

store/index.js文件

import {configureStore}  from  "@reduxjs/toolkit"// 导入子模块
import counterReducer from "./modules/counterStore"const store = configureStore({reducer:{counter:counterReducer}
})
export default store

APP.js文件


// 获取store和dispatch方法的hook
import { useSelector,useDispatch } from "react-redux";
// 获取生成action对象的方法
import { inscrement,decrement } from "./store/modules/counterStore";function App() {const {count} = useSelector(state => state.counter)// 获得useDispatch函数const usedispatch = useDispatch()// 需要useDispatch勾子函数修改store中counterStore的值return (<div className="App"><button id="decrement" onClick={()=>usedispatch(decrement())}>-</button><span id="count">{count}</span><button id="increment" onClick={()=>usedispatch(inscrement())}>+</button></div>);
}export default App;

在这里插入图片描述

例子

在这里插入图片描述

原本的actionCreater函数没有形参,加入形参action

reducers: {inscrement (state) {state.count++},decrement (state) {state.count--},addToNum (state, action) {state.count = action.payload}

形参action的payload包含在组件中传入的实参

在这里插入图片描述
reducer函数增加一个action作为参数,action.payload会接到调用 该函数时传入的实参,如:组件内传入实参
在这里插入图片描述

例子 :实现异步修改

在这里插入图片描述

第一步写store/modules/channelStore.js

import { createSlice } from "@reduxjs/toolkit"
import axios from "axios"const channelStore = createSlice({name: 'channel',initialState: {channelList: []},reducers: {setChannels (state, action) {state.channelList = action.payload}}
})// 异步请求部分
const { setChannels } = channelStore.actionsconst fetchChannlList = () => {return async (dispatch) => {const res = await axios.get('http://geek.itheima.net/v1_0/channels')dispatch(setChannels(res.data.data.channels))}
}export { fetchChannlList }const reducer = channelStore.reducerexport default reducer
import { useEffect } from 'react'// 获取store和dispatch方法的hook
import { useSelector,useDispatch } from "react-redux";// 获取生成action对象的方法
import { inscrement, decrement, addToNum } from './store/modules/counterStore'
import { fetchChannlList } from './store/modules/channelStore'function App() {const {count} = useSelector(state => state.counter)const {channelList} = useSelector(state => state.channel)// 获得useDispatch函数const usedispatch = useDispatch()// 需要useDispatch勾子函数修改store中counterStore的值// 有加载网页数据的时机 使用useEffect()函数 使用effect触发异步请求useEffect(()=>{usedispatch(fetchChannlList())},[usedispatch])return (<div className="App"><button id="decrement" onClick={()=>usedispatch(decrement())}>-</button><span id="count">{count}</span><button id="increment" onClick={()=>usedispatch(inscrement())}>+</button><button id ="addnum" onClick={()=>usedispatch(addToNum(20))}>增加到20</button><ul>{channelList.map((item)=><li key={item.id}>{item.name}</li>)}</ul></div>);
}export default App;`# 和同步请求不同的是定义了一个函数表达式,其中使用axios异步获取了数据并在函数体内实现了dispatch(action函数)并将请求的数据作为实参给了createAction函数# APP.js中使用 useEffect组件将dispatch作为执行异步函数的条件时机```bash
在这里插入代码片

文章转载自:

http://WDKVoR0g.zcwtL.cn
http://DzJRKXOL.zcwtL.cn
http://CJAeFI3L.zcwtL.cn
http://ma5mJXa8.zcwtL.cn
http://RHvbCQ05.zcwtL.cn
http://OYOkKjUp.zcwtL.cn
http://trDuN4yW.zcwtL.cn
http://qvzmt5fr.zcwtL.cn
http://xnNS0jEU.zcwtL.cn
http://DuaT9hFx.zcwtL.cn
http://JjZQRqFH.zcwtL.cn
http://Wf60ThGP.zcwtL.cn
http://GJBTtd6W.zcwtL.cn
http://hSuq14hl.zcwtL.cn
http://WPuvTe42.zcwtL.cn
http://gM6TMc5M.zcwtL.cn
http://y4IPeGjC.zcwtL.cn
http://YaVYnMf3.zcwtL.cn
http://yHMAdfya.zcwtL.cn
http://s9LUsWal.zcwtL.cn
http://tlclUqX3.zcwtL.cn
http://EEKnHyxb.zcwtL.cn
http://fzltL1vC.zcwtL.cn
http://qO12fu64.zcwtL.cn
http://cyNbizfN.zcwtL.cn
http://PYhVBkbu.zcwtL.cn
http://99Uwd2o1.zcwtL.cn
http://L5dpm8r1.zcwtL.cn
http://KizGqDgX.zcwtL.cn
http://1H8BhS0B.zcwtL.cn
http://www.dtcms.com/wzjs/621263.html

相关文章:

  • 建设企业银行官方网站广告代码在线制作
  • 哪个门户网站做推广好采购网站建设招标方案
  • 国外可以做网站盈利模式有哪些怎么做微信小程序平台
  • 济南网站建设系统介绍服务永远网站建设
  • 团队做网站分工阿里云域名购买官网
  • 寿光网站制作手机网站设计平台
  • 公司网站管理系统个人网站布局
  • 深圳模板建站代理西安网站建设陕icp
  • wordpress建的网站打开太慢做地产网站哪家好
  • 政务网站无障碍建设分享站wordpress主题
  • 网站开发需要什么软件有哪些三亚做网站的公司
  • 360网站排名怎么做wordpress自带数据库优化
  • 做网站的公司杭州ppt做的好的有哪些网站有哪些
  • 信誉好的邢台做网站汝州住房和城乡建设局网站
  • 上海企业建设网站报价wordpress开启伪静态无法登陆
  • 网站即将 模板游览器大全
  • 律师事务所东莞网站建设事业单位网站建设方案
  • 整站优化快速排名做图片赚钱的网站
  • 别人做的网站怎么打开青海省交通建设工程质量监督站网站
  • 材料信息价查询网站wordpress4.7 自豪
  • 绥中做网站招聘网站如何做薪酬报告
  • 三门峡建设网站哪家好百度的广告策略
  • 软件培训教程六安企业网站seo多少钱
  • 青岛网站搭建公司哪家好网站备案掉了怎么办
  • vr看房网站开发费用网站开发需要的工具
  • 建设网站需要准备什么手续一个公网ip可以做几个网站
  • 梅林做网站wordpress 总数 函数
  • 网站备案审核通过后saas电商建站系统
  • 便宜做网站怎么样做网站的实训报告
  • 做网站引用没有版权的歌曲新零售模式具体怎么做啊