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
});
}
},
};

DVA-subscriptions的更多相关文章

  1. dva + antd + mockjs 实现基础用户管理

    1.安装dva-cli npm install dva-cli -g 2.创建应用 dva new dvadashboard   [dvadashboard为项目名]       3.安装mockjs ...

  2. dva.js 用法详解:列表展示

    本教程案例github:https://github.com/axel10/dva_demo-Counter-and-list/tree/master 这次主要通过在线获取用户数据并且渲染成列表这个案 ...

  3. React框架 dva 和 mobx 的使用感受

    最近在用react写web项目,领导为了让前端便于维护要求都用react作为开发基础,框架选型不限.在使用 react 的时候或多或少会接触到状态管理,从开始学 react 到现在也挺久了,做一些前端 ...

  4. dva.js 上手

    来源:https://pengtikui.cn/dva.js-get-started/ ——------------------------------------------------------ ...

  5. dva,清除模块数据

    前言: 在项目中,模块过多,dva使用namespace分离模块后,若没有在模块卸载后清除对应的数据,下次进入时,有可能会有上一次数据的残留. 比如详情页,从A商品的详情页离开后,返回选择B商品进入, ...

  6. dva 知识点

    dva中,路由模式从hashHistory换成 browserHistory: dva-cli创建的项目中,src/index.js相应部分修改如下: import browserHistory fr ...

  7. 003-and design-dva.js 知识导图-02-Reducer,Effect,Subscription,Router,dva配置,工具

    一.Reducer reducer 是一个函数,接受 state 和 action,返回老的或新的 state .即:(state, action) => state 增删改 以 todos 为 ...

  8. 002-and design-基于dva的基本项目搭建

    一.概述 在真实项目开发中,你可能会需要 Redux 或者 MobX 这样的数据应用框架,Ant Design React 作为一个 UI 库,可以和任何 React 生态圈内的应用框架搭配使用.我们 ...

  9. dva subscription的使用方法

    import { routerRedux } from 'dva/router' export default { namespace: 'notice', state: { notices:[], ...

  10. Vuex、Flux、Redux、Redux-saga、Dva、MobX

    https://www.jqhtml.com/23003.html 这篇文章试着聊明白这一堆看起来挺复杂的东西.在聊之前,大家要始终记得一句话:一切前端概念,都是纸老虎. 不管是Vue,还是 Reac ...

随机推荐

  1. SQL-W3Chool-高级:SQL CREATE DATABASE 语句

    ylbtech-SQL-W3Chool-高级:SQL CREATE DATABASE 语句 1.返回顶部 1. CREATE DATABASE 语句 CREATE DATABASE 用于创建数据库. ...

  2. php+mysql模糊查询功能

    一般模糊查询语句如下: SELECT 字段 FROM 表 WHERE 某字段 Like 条件 其中关于条件,SQL提供了四种匹配模式: 1,% :表示任意0个或多个字符.可匹配任意类型和长度的字符,有 ...

  3. 阶段5 3.微服务项目【学成在线】_day05 消息中间件RabbitMQ_1.页面发布-需求分析

    先静态化,并存储到gridFS 然后,发消息给MQ,MQ接收到消息通知给所有监听他的Cms Client. Cms client从gridFS读取页面下载到自己的服务 业务流程如下:1.管理员进入管理 ...

  4. django安装xadmin中出现的报错汇总

    报错一:ModuleNotFoundError: No module named 'django.core.urlresolvers' ModuleNotFoundError: No module n ...

  5. java调用js脚本

    有些情况下,需要java去调用js,groovy等脚本语言,传入参数获取脚本运行的结果. js脚本例子: function add(a,b){ return a + b + number; } jav ...

  6. Course1_Week1_ProgrammingHomeWork

    Exercise 1: Pascal's Triangle The following pattern of numbers is called Pascal's triangle. 1 1 1 1 ...

  7. 【转】TCP/IP网络协议各层首部

    ​ 数据包封装流程(逐层封装,逐层解封) 二层帧(二层帧中目的地址6个字节,源地址6个字节,长度/类型2个字节,二层帧共18个字节) ip头部(ip头部20字节) tcp头部(tcp头部20个字节): ...

  8. Awvs–网络漏洞扫描工具

    Awvs漏洞扫描自动化 在WEB安全方面,安全侧使用Acunetix_Web_Vulnerability_Scanner_11.xWEB漏洞扫描工具定期手工对m站和www站进行全站漏洞扫描. 为了防止 ...

  9. 一文带你了解babel-preset-env

    参考链接:https://www.jianshu.com/p/000c2670672b

  10. postgresSQL常用命令

    1.createdb 数据库名称  产生数据库2.dropdb  数据库名称  删除数据库 3.CREATE USER 用户名称  创建用户4.drop User 用户名称  删除用户 5.SELEC ...