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 ...
随机推荐
- Express框架开发知识点总结
express --view=pug myapp 以上语句在当前工作目录中创建名为 myapp 的 Express 应用程序,采用的模板是jade. 以前还在纠结使用hbs模板引擎或者ejs模板,实际 ...
- Netty解码器相关文章
最通用TCP黏包解决方案:LengthFieldBasedFrameDecoder和LengthFieldPrepender https://blog.csdn.net/u010853261/arti ...
- C++ replace replace_if replace_copy replace_copy_if
#include <iostream>#include <list>#include <algorithm>#include <iterator>#in ...
- Linux 全盘搜索关键字
grep -Ern -o '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25 ...
- 一百三十五:CMS系统之UEditoe编辑器集成以及配置将图片上传到七牛
富文本编辑框,选择UEditor 下载地址:http://ueditor.baidu.com/website/download.html 使用说明:http://fex.baidu.com/uedit ...
- 使用VLC发送TS流与播放TS流
使用VLC发送TS流与播放TS流 一.如何使用VLC发送TS流 1.添加一个文件至VLC 2.选择串流,继续 3.选择UDP,点击添加 4.输入地址及端口 5.选择h.264+mp3(TS) 6.ne ...
- [转]js禁止微信浏览器下拉显示黑底查看网址,不影响内部Scroll
原贴:https://www.cnblogs.com/jasonwang2y60/p/6848464.html 原贴:https://www.cnblogs.com/jasonwang2y60/p/6 ...
- Linq Introduce
Linq学习网址: http://www.java2s.com/Code/CSharp/LINQ/CatalogLINQ.htm
- Python字符串逐字符或逐词反转方法
Python字符串逐字符或逐词反转方法 这篇文章主要介绍了Python字符串逐字符或逐词反转方法,本文对逐字符或逐词分别给出两种方法,需要的朋友可以参考下 目的 把字符串逐字符或逐词反转过来,这个蛮有 ...
- Sprint Retrospective - 回顾的重要性
在Scrum中,每个Sprint结束的时候会有两个会议(Sprint Review/Demo和Sprint Retrospective回顾).这两个会议是对过去的一个Sprint的一个总结,其中Rev ...