請檢查是否引入了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的。
