DVA-subscriptions
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的更多相关文章
- dva + antd + mockjs 实现基础用户管理
1.安装dva-cli npm install dva-cli -g 2.创建应用 dva new dvadashboard [dvadashboard为项目名] 3.安装mockjs ...
- dva.js 用法详解:列表展示
本教程案例github:https://github.com/axel10/dva_demo-Counter-and-list/tree/master 这次主要通过在线获取用户数据并且渲染成列表这个案 ...
- React框架 dva 和 mobx 的使用感受
最近在用react写web项目,领导为了让前端便于维护要求都用react作为开发基础,框架选型不限.在使用 react 的时候或多或少会接触到状态管理,从开始学 react 到现在也挺久了,做一些前端 ...
- dva.js 上手
来源:https://pengtikui.cn/dva.js-get-started/ ——------------------------------------------------------ ...
- dva,清除模块数据
前言: 在项目中,模块过多,dva使用namespace分离模块后,若没有在模块卸载后清除对应的数据,下次进入时,有可能会有上一次数据的残留. 比如详情页,从A商品的详情页离开后,返回选择B商品进入, ...
- dva 知识点
dva中,路由模式从hashHistory换成 browserHistory: dva-cli创建的项目中,src/index.js相应部分修改如下: import browserHistory fr ...
- 003-and design-dva.js 知识导图-02-Reducer,Effect,Subscription,Router,dva配置,工具
一.Reducer reducer 是一个函数,接受 state 和 action,返回老的或新的 state .即:(state, action) => state 增删改 以 todos 为 ...
- 002-and design-基于dva的基本项目搭建
一.概述 在真实项目开发中,你可能会需要 Redux 或者 MobX 这样的数据应用框架,Ant Design React 作为一个 UI 库,可以和任何 React 生态圈内的应用框架搭配使用.我们 ...
- dva subscription的使用方法
import { routerRedux } from 'dva/router' export default { namespace: 'notice', state: { notices:[], ...
- Vuex、Flux、Redux、Redux-saga、Dva、MobX
https://www.jqhtml.com/23003.html 这篇文章试着聊明白这一堆看起来挺复杂的东西.在聊之前,大家要始终记得一句话:一切前端概念,都是纸老虎. 不管是Vue,还是 Reac ...
随机推荐
- java基于jcifs.smb实现远程发送文件到服务器
1.服务器指定共享文件夹 1.1.验证服务器共享文件夹本地可以访问: 2.导入依赖的相关jar包 jcifs-1.3.**.jar: <dependency> <gr ...
- SQL-W3School-基础:SQL DISTINCT 语句
ylbtech-SQL-W3School-基础:SQL DISTINCT 语句 1.返回顶部 1. 本章讲解 SELECT DISTINCT 语句. SQL SELECT DISTINCT 语句 在表 ...
- 关于axios如何在请求头添加参数
vm.$http.post(apiUrl.refundOrder, data,{ headers:{ 'lz-shopid':vm.orderRecords.shopId } }).then(res ...
- labelme
项目:https://github.com/wkentaro/labelme?tdsourcetag=s_pcqq_aiomsg 说明:https://www.bilibili.com/video/a ...
- JAVA 基础编程练习题36 【程序 36 移动位置】
36 [程序 36 移动位置] 题目:有 n 个整数,使其前面各数顺序向后移 m 个位置,最后 m 个数变成最前面的 m 个数 package cskaoyan; public class cskao ...
- python封装和解构
封装 将多个值使用逗号分割,组合在一起 本质上,返回一个元组,只是省略了小括号 python的特有的语法,被很多语言学习借鉴 t1 = (1,2) #定义元组 t2 = 1,2 #将1和2封装成元组 ...
- unity3d 触屏多点触控(旋转与缩放)
unity3d 触屏多点触控(旋转与缩放) /*Touch OrbitProgrammed by: Randal J. Phillips (Caliber Mengsk)Original Creati ...
- Ubuntu 16.04 RabbitMq 安装与运行
前言目前公司用阿里云 + redis 的方式实现的消息队列.了解了目前几种主流的消息组件(主要包括rabbitmq.kafka.)的优缺点后,这里为了深入学习rabbitmq,我在自己的腾讯云服务器上 ...
- Jmeter 逻辑控制器 之 Runtime Controller
一.认识 Runtime Controller 控制其下样例执行的时间长度. 设置界面: Runtime (seconds):运行时间,单位秒.即控制其下样例执行多长时间.与线程组中的调度器的持续 ...
- Jmeter 逻辑控制器 之 Include Controller
一.认识 Include Controller Include Controller :译为包含控制器,用来添加 Test Fragment(测试片段).具体是什么意思呢,我们先来了解下 Test F ...