从缓存中检索的数据已返回,但未显示在页面上

问题描述

我使用的是 ASP.NET Core Web API。这里有一个中间件,如果传入请求的响应在缓存中可用,我在响应中将其发送回来。

我可以在不使用缓存的情况下检索所有数据并在我发出的请求中在页面上查看它。

但是,当我使用缓存时,我仍然检索数据,但是当我尝试查看它时,数据未定义,无法显示

我不明白是什么导致了这个问题。

请求

export function getCategories() {
return async function (dispatch,getState) {
    await axios.get(CATEGORIES_PATH).then((res) => {
        dispatch(getCategoriesSuccess(res.data))
        console.log("categories:",res.data);
        return res.data;
    }).catch(err => redirectErrPage(err,dispatch));
}}

反应

class CategoryList extends Component {

componentDidMount() {
    this.props.actions.getCategories();
}
render() {
    return (
        <div >
            <ListGroup className="shadow-lg">
                <ListGroupItem >
                    <h5>
                        {
                            this.props.categories.map(c => (
                                <Link key={c.id} to={"/Feed/" + encodeURIComponent(c.name)} className="text-decoration-none"> <Badge
                                    variant="info"
                                    className="ml-2 mt-2 cursorPointer category "
                                >{c.name}</Badge></Link>
                            ))
                        }
                    </h5>
                </ListGroupItem>
            </ListGroup>
        </div>
    )
}}

function mapStatetoProps(state) {
    return { categories: state.categoryListReducer,selectedCategories: state.selectedCategoriesReducer }
}
function mapdispatchToProps(dispatch) {
    return {
        actions: {
            getCategories: bindActionCreators(categoryAsyncActions.getCategories,dispatch)
        }
    }
}
export default connect(mapStatetoProps,mapdispatchToProps)(CategoryList);

无缓存

Redux

enter image description here

enter image description here

带缓存

Redux

enter image description here

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)