在react中利用redux和fetch获取数据并渲染到页面该怎么做

2025-03-29 16:55:40
推荐回答(1个)
回答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
});
};
}