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

有了域名空间怎么做网站wordpress 摘要 图片

有了域名空间怎么做网站,wordpress 摘要 图片,做国外网站用国内服务器,个人网页制作教程代码reactredux异步操作数据 redux中操作异步方法#xff0c;主要是#xff1a; 1、借助createAsyncThunk()封装异步方法#xff1b;2、通过extraReducers处理异步方法触发后的具体逻辑#xff0c;操作派生的state 1、异步操作的slice import { createSlice, createAsyncThunk…reactredux异步操作数据 redux中操作异步方法主要是 1、借助createAsyncThunk()封装异步方法2、通过extraReducers处理异步方法触发后的具体逻辑操作派生的state 1、异步操作的slice import { createSlice, createAsyncThunk } from reduxjs/toolkit// 使用该类型定义初始 state const initialState {systemName: 三分之一 } // promise封装的定时器 function delay(ms: number, data: string) {return new Promise((resolve) setTimeout(() resolve(data), ms)) } // AsyncThunkvoid, void, AsyncThunkConfig // createAsyncThunkstring, string, object : // 第一个string: system/updateSystemName // 第二个string: updateSystemName调用时传的参数 // object AsyncThunkConfig 配置对象 // 详细可见 https://redux-toolkit.js.org/usage/usage-with-typescript#createasyncthunk export const updateSystemName createAsyncThunkstring, string(system/updateSystemName,async (data, config): Promisestring {console.log(data, config)const res await delay(2000, data)return res as string} )const systemSlice createSlice({name: system,initialState,reducers: {},extraReducers: (builder) {// 触发updateSystemName执行builder.addCase的回调builder.addCase(updateSystemName.fulfilled, (state, action) {// action: {// type: system/updateSystemName/fulfilled// },// payload: dispatch(updateSystemName(单点的)) updateSystemName// meat: {arg: 单点的, ...}state.systemName action.payload})} }) export default systemSlice.reducerAsyncThunkConfig 如图所示 2、组件中调用异步的方法 import { updateSystemName } from /store/reducers/systemSlice import { RootState } from /store import { useAppDispatch } from /hooks/useAppDispatch import { useAppSelector } from /hooks/useAppSelectorconst Home () {const { systemName } useAppSelector((state: RootState) state.systemReducer)const dispatch useAppDispatch()const test () {// useDispatch() 返回值函数默认期望的参数类型是 AnyAction// 异步处理是updateSystemName AsyncThunkAction// 所以这块使用官网推荐的自定义封装的hooks useAppDispatchdispatch(updateSystemName(单点的))}return (divhome page/divp{systemName}/pbutton onClick{test}测试/button/) }export default Home4、给dispatch()参数添加Action类型 解决 类型“AsyncThunkActionstring, string, AsyncThunkConfig”的参数不能赋给类型“AnyAction”的参数。 useAppDispatch import type { AppDispatch } from /store import { useDispatch } from react-redux// 给useDispatch 添加泛型 默认接收的参数是AnyAction // import { useDispatch } from react-redux export const useAppDispatch () useDispatchAppDispatch()useAppSelector import type { RootState } from /store import { TypedUseSelectorHook, useSelector } from react-redux// import { useSelector } from react-redux export const useAppSelector: TypedUseSelectorHookRootState useSelectorstore中 export type RootState ReturnTypetypeof store.getState export type AppDispatch typeof store.dispatch import { configureStore } from reduxjs/toolkit import { combineReducers } from redux // 数据持久化 import { persistStore, persistReducer } from redux-persist import storageLocation from redux-persist/lib/storage // defaults to localStorage for web // redux-persist/lib/storage/session // reducers import userReducer from ./reducers/userSlice import systemReducer from ./reducers/systemSlice const persistConfig {key: root,storage: storageLocation } // 持久化reducers const persistedReducer persistReducer(persistConfig,combineReducers({//数据切片userReducer,systemReducer}) )const store configureStore({// userReducer 模块名reducer: persistedReducer,middleware: (getDefaultMiddleware) getDefaultMiddleware({serializableCheck: false}) })// 可以订阅 store // store.subscribe(() console.log(store.getState(), userSlice))// 持久化的store const persistor persistStore(store)export { store, persistor }// Infer the RootState and AppDispatch types from the store itself export type RootState ReturnTypetypeof store.getState // Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState} export type AppDispatch typeof store.dispatch
http://wiki.neutronadmin.com/news/237928/

相关文章:

  • 数码家电商城网站源码怎么申请网上店铺
  • 清远企业网站建设公司wordpress站标签也打不开
  • 世界杯直播观看网站智慧团建网站登陆
  • 邯郸做seo网站优化贵州省住房与城乡建设厅门户网站
  • 拓者设计吧官方网站岳阳建设公司网站
  • 长期网站外包ps网页设计教程及素材
  • 中国风格网站模板深圳网络推广网站
  • wordpress建站教程潜江资讯网
  • 徐州网站建设推广如何做网站步骤
  • 哪里有做响应式网站的广丰网站seo
  • 响应式网站公司淮海中路街道网站建设
  • 做网站推荐泰安搜索引擎优化招聘
  • 网站 支付宝 接口广东东远建设工程管理有限公司网站
  • 铜陵市建设局网站百度收录多的是哪些网站
  • 男人和女人做不可描述的事情的网站网站制作费用多少钱
  • 网站制作公司挣钱吗做的网站怎么提交到百度上去
  • 网站优化seo是什么模具钢东莞网站建设
  • c2c网站页面设计特点114信息网免费发布信息
  • 龙信建设集团网站公司宣传片广告
  • 购物商城网站开发公司金坛常州做网站
  • 设计工作室 网站珠海网站制作套餐
  • 素材网站开发c++后端开发需要学什么
  • 装修设计网站排名wordpress电影站群
  • 图文店做网站有用处吗网站建设应具备哪些专业技能
  • 安徽建设工程安全监督网站上海网站建设 网页制作
  • 企业网站建设难吗百度关键词排名推广工具
  • 灵璧县住房和城乡建设局网站高端网站建设免费分析
  • 中小企业网站规划方案做a 需要制作网站
  • 可以网站可以做免费的文案广告商品关键词怎么优化
  • flash网站怎么制作外包优化网站