Javascript 无法读取属性';然后';未定义的
所以我使用react+redux,并且我继续得到以下错误:“无法读取未定义的'then'属性”。由于某种原因,这个承诺没有得到回报。我对使用redux thunk也特别陌生 减速器Javascript 无法读取属性';然后';未定义的,javascript,redux,react-redux,redux-thunk,Javascript,Redux,React Redux,Redux Thunk,所以我使用react+redux,并且我继续得到以下错误:“无法读取未定义的'then'属性”。由于某种原因,这个承诺没有得到回报。我对使用redux thunk也特别陌生 减速器 import { merge } from 'lodash'; import * as APIutil from '../util/articles_api_util'; import { ArticleConstants } from '../actions/article_actions'; con
import { merge } from 'lodash';
import * as APIutil from '../util/articles_api_util';
import {
ArticleConstants
} from '../actions/article_actions';
const ArticlesReducer = (state = {}, action) => {
switch (action.type) {
case ArticleConstants.RECEIVE_ALL_ARTICLES:
debugger
return merge({}, action.articles);
default:
return state;
}
};
export default ArticlesReducer;
商店
import { createStore, applyMiddleware } from 'redux';
import RootReducer from '../reducers/root_reducer';
import thunk from 'redux-thunk';
import * as APIUtil from '../util/articles_api_util';
export const ArticleConstants = {
RECEIVE_ALL_ARTICLES: "RECEIVE_ALL_ARTICLES",
REQUEST_ALL_ARTICLES: "REQUEST_ALL_ARTICLES"
}
行动
export function fetchArticles() {
return function(dispatch) {
return APIUtil.fetchArticles().then(articles => {
dispatch(receiveAllArticles(articles));
}).catch(error => {
throw(error);
});
};
}
export const requestAllArticles= () => ({
type: REQUEST_ALL_ARTICLES
});
export const receiveAllArticles = articles => ({
type: RECEIVE_ALL_ARTICLES,
articles
});
const configureStore = (preloadedState = {}) => (
createStore(
RootReducer,
preloadedState,
applyMiddleware(thunk)
)
);
export default configureStore;
APIUtil
export const fetchArticles = (success) => {
$.ajax({
method: 'GET',
url: `/api/articles`,
success,
error: ()=> (
console.log("Invalid Article")
)
});
};
如果不使用花括号,则箭头函数只会隐式返回s。一旦包含大括号,就定义了函数体,并且需要显式地
返回值
您的fetchArticles
函数被编写为带花括号的箭头函数。但是,您没有显式返回调用$.ajax()
的结果。因此,函数的返回值是未定义的
,并且没有返回的承诺可以链接。您是否也可以共享APIUtil.fetchArticles
method@Swapnil我添加了一个APIUtilDid,您尝试使用.done
代替。然后
我得到了相同的未定义错误,但现在不是。而是。完成每个简单的解决方案:更新您的文件并尝试使用更新的sweetalert.min.js。我也面临同样的问题,但在更新后我修复了它。