在react中利用redux和fetch获取数据并渲染到页面该怎么做
1个回答
展开全部
actions:
export const getMenu = () => {
return async (dispatch) => {
let msg = await fetch('data/nodes',{
method: 'POST',
//body: JSON.stringify({"aa":"aa"}),
header: {'content-type':'application/json; charset=utf-8'}
}).then((res)=>res.json());
var state = { nodes: msg };
dispatch({
type: 'INIT',
state
});
};
}
export const getMenu = () => {
return async (dispatch) => {
let msg = await fetch('data/nodes',{
method: 'POST',
//body: JSON.stringify({"aa":"aa"}),
header: {'content-type':'application/json; charset=utf-8'}
}).then((res)=>res.json());
var state = { nodes: msg };
dispatch({
type: 'INIT',
state
});
};
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询