Javascript 如何使用react redux在wordpress rest api中获取类别

Javascript 如何使用react redux在wordpress rest api中获取类别,javascript,wordpress,reactjs,redux,react-redux,Javascript,Wordpress,Reactjs,Redux,React Redux,我正在尝试使用redux从wordpress rest api获取reactjs中的类别名称 actions/categories.js reducers/categories.js reducers/index.js 我试着用同样的方法得到这个职位,结果成功了。但在分类的情况下,它什么也没有给出。我甚至尝试在action/categories.js中使用console.log(res),但在浏览器中没有给出响应。任何人请向我解释为什么会发生这种情况 这就是我试图呈现这个sideDrawer.j

我正在尝试使用redux从wordpress rest api获取reactjs中的类别名称

actions/categories.js

reducers/categories.js

reducers/index.js

我试着用同样的方法得到这个职位,结果成功了。但在分类的情况下,它什么也没有给出。我甚至尝试在action/categories.js中使用console.log(res),但在浏览器中没有给出响应。任何人请向我解释为什么会发生这种情况

这就是我试图呈现这个sideDrawer.js的地方

从“React”导入React
从“@material ui/core/Drawer”导入抽屉;
从“@material ui/core/List”导入列表;
从“@material ui/core/Divider”导入分隔器;
从“@material ui/core/IconButton”导入IconButton;
从“@material ui/icons/ChevronLeft”导入ChevronLeftIcon;
从“@material ui/icons/ChevronRight”导入ChevronRightIcon;
从“@material ui/core/ListItem”导入ListItem;
从“@material ui/core/ListItemIcon”导入ListItemIcon;
从“@material ui/core/ListItemText”导入ListItemText;
从“@material ui/icons/MoveToInbox”导入InBoxion;
从“@material ui/icons/Mail”导入MailIcon;
从'react redux'导入{connect};
从“../actions/categories”导入{getCategories};
函数侧抽屉({handleDrawerClose,open,Class,theme}){
返回(
{theme.direction=='ltr'?:}
{['Inbox','Starred','Send email','Drafts'].map((文本,索引)=>(
{索引%2==0?:}
))}
{['All mail','Trash','Spam'].map((文本,索引)=>(
{索引%2==0?:}
))}
)
}
常量mapStateToProps=状态=>({
类别:state.categories.categories
})
导出默认连接(mapStateToProps,{getCategories})(SideDrawer);
import axios from 'axios';
import { GET_CATEGORIES } from './types';


export const getCategories = () => dispatch => {
    axios.get('/wp-json/wp/v2/categories')
        .then(res => {
            console.log(res);
            dispatch({
                type: GET_CATEGORIES,
                payload: res.data
            });
        }).catch(err => console.log(err));
}
import {GET_CATEGORIES} from '../actions/types';

const initialState = {
    categories: []
}

export default function (state = initialState, action) {
    switch (action.type) {
        case GET_CATEGORIES:
            return {
                ...state,
                categories: action.payload
            }
        default:
            return state;
    }
}
import {combineReducers} from 'redux';
import posts from './posts';
import categories from './categories';
export default combineReducers({
    posts,
    categories
});
import React from 'react'
import Drawer from '@material-ui/core/Drawer';
import List from '@material-ui/core/List';
import Divider from '@material-ui/core/Divider';
import IconButton from '@material-ui/core/IconButton';
import ChevronLeftIcon from '@material-ui/icons/ChevronLeft';
import ChevronRightIcon from '@material-ui/icons/ChevronRight';
import ListItem from '@material-ui/core/ListItem';
import ListItemIcon from '@material-ui/core/ListItemIcon';
import ListItemText from '@material-ui/core/ListItemText';
import InboxIcon from '@material-ui/icons/MoveToInbox';
import MailIcon from '@material-ui/icons/Mail';
import { connect } from 'react-redux';
import {getCategories} from '../actions/categories';

function SideDrawer({ handleDrawerClose, open, classes, theme}) {

  return (
    <Drawer
          className={classes.drawer}
          variant="persistent"
          anchor="left"
          open={open}
          classes={{
            paper: classes.drawerPaper,
          }}
        >
          <div className={classes.drawerHeader}>
            <IconButton onClick={handleDrawerClose}>
              {theme.direction === 'ltr' ? <ChevronLeftIcon /> : <ChevronRightIcon />}
            </IconButton>
          </div>
          <Divider />
          <List>
            {['Inbox', 'Starred', 'Send email', 'Drafts'].map((text, index) => (
              <ListItem button key={text}>
                <ListItemIcon>{index % 2 === 0 ? <InboxIcon /> : <MailIcon />}</ListItemIcon>
                <ListItemText primary={text} />
              </ListItem>
            ))}
          </List>
          <Divider />
          <List>
            {['All mail', 'Trash', 'Spam'].map((text, index) => (
              <ListItem button key={text}>
                <ListItemIcon>{index % 2 === 0 ? <InboxIcon /> : <MailIcon />}</ListItemIcon>
                <ListItemText primary={text} />
              </ListItem>
            ))}
          </List>
        </Drawer>
  )
}
const mapStateToProps = state => ({
    categories: state.categories.categories
})
export default connect(mapStateToProps, {getCategories})(SideDrawer);