这是我的createAsyncThunk的样子
export const fetchMapData = createAsyncThunk(
'mapdata/fetchMapData',
async (id) => {
const response = await axios.get(
GLOBALVIEWS_API,
{
headers: {
'Content-Type': 'application/json',
'X-API-KEY': HBO_KEY,
},
params: {
titleId: id,
}
}
)
return response.data.Item;
}
)
,我需要把它变成一个createApi(),但下面的仍然是失败的参数要求
export const apiSlice = createApi({
reducerPath: 'api',
baseQuery: fetchBaseQuery({
baseUrl: BASE_URL,
prepareHeaders: (headers, { getState }) => {
headers.set('Content-Type', 'application/json')
headers.set('X-API-KEY', HBO_KEY)
return headers
}
}),
endpoints:(builder) => ({
getMedia: builder.query({
query:(id) => {
console.log("titleId: ", id);
return{
url: '/titlestest',
params: {titleId: id}
}
}
})
})
})
export const apiSlice = createApi({
reducerPath: 'api',
baseQuery: fetchBaseQuery({
baseUrl: BASE_URL,
prepareHeaders: (headers, { getState }) => {
headers.set('Content-Type', 'application/json')
headers.set('X-API-KEY', HBO_KEY)
return headers
}
}),
endpoints:(builder) => ({
getMedia: builder.query({
query: (id) => `/titletest/${id}`,
// or
query: (id) => ({ url: `/titletest/${id}` }),
// or
query: ({ title, id }) => `/${title}/${id}`,
})
})
})