这是我的服务,我在其中调用api(带参数)
const battle = async (obj:any): Promise<result[]> =>{
const data=await fetch(`${API_URL}`,{
method: "POST",
// Adding body or contents to send
body: JSON.stringify({
"1stArg": obj.arg1,
"2ndArg": obj.arg2
}),
// Adding headers to the request
headers: {
"Content-type": "application/json; charset=UTF-8"
}
});
const res = await data.json()
return res;
}
这是我调用该服务的操作
export const getResult=createAsyncThunk<result[]>(
'testing/getResult',
async(obj:any)=>{
const data= await services.battle(obj);
return data;
}
);
这是减速器
builder.addCase(getResult.pending, (state) => ({
...state,
result: null,
}));
builder.addCase(getResult.rejected, (state) => ({
...state,
result: null,
}));
builder.addCase(getResult.fulfilled, (state, action) => ({
...state,
result: action.payload,
}));
选择器
export const getFinalResult = (state: RootState) => state.monsters.result;
这就是我如何使用
const result=useSelector(getFinalResult);
const handleStartBattleClick = () => {
let obj={
fistArg,2ndArg
}
dispatch(getResult(obj))
}
而得到这个错误
应为0个参数,但得到1个
1条答案
按热度按时间jvlzgdj91#
如果在上面指定了泛型,则必须完全指定:
否则,它将退回到
void
,这意味着“无参数”。