参考antd-admin在开发登录界面,目前点击提交按钮后,
一:调用到了model下的loginModel.js的login方法,loginModel.js 代码如下:
import { login } from '../services/login'
import { routerRedux } from 'dva/router'
import { queryURL } from 'utils'
export default {
namespace: 'loginModel',
state: {
loginLoading: false,
},
effects: {
*login({
payload,
}, { put, call }) {
yield put({ type: 'showLoginLoading' })
const data = yield call(login, payload)
yield put({ type: 'hideLoginLoading' })
if (data.success) {
const from = queryURL('from')
yield put({ type: 'app/query' })
if (from) {
yield put(routerRedux.push(from))
} else {
yield put(routerRedux.push('/dashboard'))
}
} else {
throw data
}
},
},
reducers: {
showLoginLoading(state) {
return {
...state,
loginLoading: true,
}
},
hideLoginLoading(state) {
return {
...state,
loginLoading: false,
}
},
},
};
二:loginModel.js中的login方法中call到了services下的login.js脚本中的login方法,login.js代码如下:
通过打印输出,url是非空的。
import { request, config } from 'utils'
const { api } = config
const { userLogin } = api
export async function login (data) {
return request({
url: userLogin,
method: 'get',
data,
})
}
三:login.js调用了request.js中的request方法,fetch也有执行,下面是request.js代码:
import fetch from 'dva/fetch';
function parseJSON(response) {
// return response.json();
return null;
}
function checkStatus(response) {
if (response.status >= 200 && response.status < 300) {
return response;
}
const error = new Error(response.statusText);
error.response = response;
throw error;
}
export default function request(url, options) {
return fetch(url, options)
.then(checkStatus)
.then(parseJSON)
.then(data => ({ data }))
.catch(err => ({ err }));
}
四,request.js中的fetch执行后,浏览器console中打印出如下错误内容:
uncaught at _callee3
at _callee6
at takeEvery(loginModel/login, sagaWithCatch)
at sagaWithCatch
Error: [object Object]
at http://localhost:8000/index.js:12206:16
at http://localhost:8000/index.js:24392:27
at onErrorWrapper (http://localhost:8000/index.js:12211:12)
at sagaWithCatch$ (http://localhost:8000/index.js:12570:18)
at tryCatch (http://localhost:8000/index.js:12841:41)
at Generator.invoke [as _invoke] (http://localhost:8000/index.js:13079:23)
at Generator.prototype.(anonymous function) [as throw] (http://localhost:8000/index.js:12893:22)
at next (http://localhost:8000/index.js:22415:33)
at Object.currCb [as cont] (http://localhost:8000/index.js:22514:8)
at end (http://localhost:8000/index.js:22481:24)
同时浏览器network中并未发现有请求发出,截图如下:

求教大家这怎么解决?
@sorrycc
我也遇到了,请问你解决了吗?
我知道了,你的request接受2个参数,你传了一个对象
function request(url, options)
所以你的调用应该是:
request(userLogin, {
method: 'get',
data,
})
这样的吧
@sorrycc 请问这个问题怎么解决啊大神
@loccmodd 请问你这个问题怎么解决的啊?我也遇到了这样的问题,教教我啊
解决了吗,我也遇到了。不知道出错在哪里。
@LeezQ @wupinlang 即使是参数问题,也不能造成程序crash!
@zoushenglin 是不是出现这个报错程序就崩溃了
got this problem too. I solved it in the following way: when getting error from request then I return resolved promise with {success: false} instead of rejected one
怎么解决的?也没个回答了啊···
const app = dva({
onAction: middlewares,
onError: (err, dispatch) => {
if (err.response) {
}
}
})
catch the error in index file @zhangyang110
request( ${userLogin}${params} )这样就解决了
Most helpful comment
got this problem too. I solved it in the following way: when getting error from request then I return resolved promise with {success: false} instead of rejected one