javaLuo / react-luo

React Automatically - 保持最新技术 react18 hooks router6 webpack5 babel7 antd4
https://isluo.com/work/pwa/
MIT License
312 stars 71 forks source link

您好,我想再次请教个问题,麻烦了 #3

Closed wangjunwei910208 closed 7 years ago

wangjunwei910208 commented 7 years ago

export const editProblem=(obj)=>{ Fetchapi.newPost( 'url',obj ).then( msg => { console.log(msg); dispatch(xxxAction); } ).catch(() => { message.error('网络错误,请重试'); }); } 这个我写的一个函数(写在了一个公共函数的js文件里),我想在异步时的then()函数里请求成功时发送action,如上,但提示dispatch未定义,请问我怎么把dispatch弄进来

javaLuo commented 7 years ago

如果你要这样export出去的话。

` // 在组件页面的顶部引入两个东西: import { bindActionCreators } from 'redux'; import { editProblem} from '../../a_action/app-action';

// 页面的底部这样写 export default connect( (state) => ({ }), (dispatch) => ({ actions: bindActionCreators({ editProblem}, dispatch), }), )(TestPageContainer); `

wangjunwei910208 commented 7 years ago

好的 谢谢!