dvajs / dva

🌱 React and redux based, lightweight and elm-style framework. (Inspired by elm and choo)
https://dvajs.com/
MIT License
16.25k stars 3.16k forks source link

loading.effects与createLogger一起使用后监听状态的问题 #2414

Closed Jiyr0119 closed 3 years ago

Jiyr0119 commented 3 years ago

What happens?

image 不存在的用户接口报错,状态400。之后就不会走到 dva hide

import` { createLogger } from 'redux-logger';
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage'; // defaults to localStorage for web

// redux 持久化存储
const persistConfig = {
  key: 'root',
  storage,
  whitelist: ['userAndlogin'],
};

const persistEnhancer = () => (createStore) => (reducer, initialState, enhancer) => {
  const store = createStore(persistReducer(persistConfig, reducer), initialState, enhancer);
  const persist = persistStore(store, null);
  return { ...store, persist };
};

// 解决生产环境打包报错
// const data =
//   process.env.NODE_ENV === 'production'
//     ? {}
//     : {
//         onError(err) {
//           err.preventDefault();
//         },
//         onAction: createLogger(),
//       };

export const dva = {
  config: {
    extraEnhancers: [persistEnhancer()],
    onReducer: (reducer) => persistReducer(persistConfig, reducer),
    // ...data,
    onError(err) {
      err.preventDefault();
    },
    onAction: createLogger(),
  },
};

然后我发现我本地没问题 部署有问题 我就试了一下 都使用 logger 就没问题了。我的理解是跟这个插件有冲突,因为当时初始化的版本是没有appjs来配置 dva的一些东西的。现在解决了 但是部署之后的版本也能看到log 来寻求大佬们的帮助

最小可复现仓库

请使用 yarn create umi 创建,选择 app,然后选上 dva,并上传到你的 GitHub 仓库

复现步骤,错误日志以及相关配置

相关环境信息

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.