在获取HTTP请求中传递查询数据参数

问题描述 投票:0回答:1

因此,我的Recipe的后端生成App的Get HTTP端点接受params并根据路由中传递的参数操纵响应。

例如:如果我想收到仅属于某些美食组的食谱,我可以通过我的获取HTTP请求传递这些美食组

"http://myrecipe.com/get/recipes/?cuisine=mediterranean&&cuisine=indian&&cuisine=chinese

这是我的action.js

export const getRecipes = (params, access_token) => async dispatch => {
  const res = await axios.get(
          '/api/recipes'), 
          { params: {} }, 
          {headers: Authorization: `Bearer ${access_token}`}
     ); 
   dispatch({
       type: GET_RECIPES,
       payload: res.data
   }); 
}

和我的组件:

componentDidMount() {
   this.props.getRecipes({params: {cuisine: 'indian', cuisine: 'chinese', cuisine='mediterranean'} }, user.access_token); 
} 

但这似乎没有用,我的代码怎么了?

reactjs redux axios redux-thunk reducers
1个回答
0
投票

这不行。使用redux-thunk或redux-saga(我推荐后者)进行异步调用。

© www.soinside.com 2019 - 2024. All rights reserved.