当前位置:   article > 正文

react 暂存数据持久化_react store 数据持久化

react store 数据持久化

> npm install redux-persist 
npm install --save redux-persist-transform-filter

  依赖 
"redux-persist": "^6.0.0",

    "redux-persist-transform-filter": "0.0.20",

src    ----->   app.js

import { persistStore, persistReducer } from 'redux-persist'

import storage from 'redux-persist/lib/storage'

const persistConfig = {   key: 'root',   storage,   whitelist: ['regionInfo','urbanInfo','shopInfo','event'], // 配置白名单 里面写需要配置的名字   }   // 数据持久化   const persistEnhancer = () => createStore => (reducer, initialState, enhancer) => {   const store = createStore(persistReducer(persistConfig, reducer), initialState, enhancer);   const persist = persistStore(store);   return {...store, persist };   }     export const dva = {   config: {   extraEnhancers: [persistEnhancer()]   }   }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/510779
推荐阅读
相关标签
  

闽ICP备14008679号