作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
user.js获取用户
import { FETCTH_FAIL, FETCTH_SUCCES, FETCTH_USER } from "../action/actionTypes";
import { put, takeLatest } from "redux-saga/effects";
import Api from "./App";
function* fetUsers() {
try {
const users = yield Api.getUsers();
yield put({ type: FETCTH_SUCCES, users: users });
} catch (err) {
yield put({ type: FETCTH_FAIL, error });
}
}
export function* watchFecthUsers() {
yield takeLatest(FETCTH_USER, fetUsers);
}
rootSaga.js rootSaga
import { call, all } from "redux-saga/effects";
import { watchFecthUsers } from "./users";
export default function* rootSaga() {
yield call(watchFecthUsers);
}
actionTypes.js Action
export const FETCTH_USER = 'fetchuser';
export const FETCTH_SUCCES = 'fetchsucces';
export const FETCTH_FAIL = 'fetchfail';
我收到下面提到的错误
D:\android_ios\sagaredux\node_modules\react-native\Libraries\Core\ExceptionsManager.js:71 uncaught at rootSaga at rootSaga
at watchFecthUsers
at takeLatest
at fetUsers
ReferenceError: error is not defined
最佳答案
我知道现在回答已经很晚了,但只是为了清楚起见,这个错误
yield put({type:FETCTH_FAIL,error});
在上面的行中,未定义“错误”,因此会发生错误。
您可以将此行更改为如下所示:
yield put({type:FETCTH_FAIL,error:err}); ,其中“err”是catch块的变量名。
关于syntax-error - 在rootSaga在watchSec上在rootSaga上未捕获,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51983038/
我是一名优秀的程序员,十分优秀!