zoukankan      html  css  js  c++  java
  • dva subscription的使用方法

    import { routerRedux } from 'dva/router'
    export default {
      namespace: 'notice',
      state: {
        notices:[],
        loading: false,
        editModalVisible: false
      },
      effects: {
        *watchAndRefreshList({ dispatch }, { put, call, take }){
          let listAction = {};
        //关闭弹框后重新获取数据
        //调用hideModal就会触发fetch
    while(true){ const action = yield take(['notice/fetch', 'notice/hideModal']); console.log('action', action); if(action.type == 'notice/fetch'){ action.type = 'fetch'; listAction = action; } if(action.type == 'notice/hideModal'){ action.type = 'hideModal'; dispatch(listAction); } } }, *fetch({ payload }, { call, put }) { const response = yield call(Get, '/api/notices'); yield put({ type: 'save', payload: response }) }, *gologin({ payload }, { call, put }) { yield put(routerRedux.push('/user/login')) } }, reducers: { save(state, action) { return { ...state, notices: action.payload } }, showModal(state, action){ return { ...state, editModalVisible: true } }, hideModal(state, action){ return { ...state, editModalVisible: false, } }, }, subscriptions: { //监听地址,如果地址含有app则跳转到登陆页 setup({ dispatch, history }) { history.listen(location => { if (location.pathname.includes('app')) { dispatch({ type: 'gologin' }) } }); }, watchAndRefreshList({ dispatch, history }){ dispatch({ type: 'watchAndRefreshList', dispatch }); } }, };
  • 相关阅读:
    c语言 作用域、存储期、链接属性汇总
    进程上下文切换分析
    进程装载过程分析(execve系统调用分析)
    fork 创建进程的过程分析
    系统调用软中断处理程序system_call分析
    linux 系统调用分析
    8分钟带你深入浅出搞懂Nginx
    控制反转
    JAVA泛型(转)
    AOP(转)
  • 原文地址:https://www.cnblogs.com/AnnieShen/p/8028231.html
Copyright © 2011-2022 走看看