2
響應我用終極版,傳奇和我創建了一個發電機checkUsername
其執行API調用。我雖然const username
將等於來自API的響應,但我得到undefined
。終極版,傳奇不會等待來自API
function* checkUsername(action) {
try {
const username = yield call(Api.checkUsername, action.username);
yield put({type: actions.USERNAME_CHECK_SUCCEEDED, username});
} catch (e) {
yield put({type: actions.USERNAME_CHECK_FAILED, message: e.message});
}
}
雖然我checkUsername
功能,調用API res
等於{"isExist": false}
:
checkUsername(username) {
fetch(url, {
'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
}
}).then(response => response.json())
.then(res => res)
.catch(error => console.error(error));
},
爲什麼我const username
不等於{"isExist": false}
?
非常感謝你! – rel1x
保存了我的一天。謝謝。! –