请检查是否引入了umi中的connect
2021/05/01 尝试去使用dispatch方法来调试数据,代码如下:
const { dispatch } = this.props;
console.log(this.props);
dispatch({
type: 'creation/updateRule',
payload: e,
}).then((result) => {
message.success(result);
if (result === 'ok') {
message.info(result)
}
});
反应:没有触发接口,没有进入dispatch方法里面
打印dispatch,结果:undefined
或者:dispatch is not a function
上网查了一下,才知道是需要引入umi的一个东西叫connect
两行代码搞定:
import { connect } from 'umi'; // 这行写在代码最上面
export default connect()(Creation);// 这行写在代码最下面 如果你只是引入了connect而没有去使用它,也就是没有这第二行代码,那么依旧还是会报undefined的。
