这是我的Api.js
export const api = createApi({
reducerPath: 'api',
baseQuery: fetchBaseQuery({
prepareHeaders: (headers, { getState }) => {
const userInfo=JSON.parse(localStorage.getItem('userInfo'))
// If we have a token set in state, let's assume that we should be passing it.
if (userInfo!==null) {
headers.set('Authorization', `Bearer ${userInfo.token}`)
}
// console.log("logingheaders",headers)
return headers
}
}),
tagTypes:['Refetchorders'],
endpoints: (builder) => ({
getMyOrders:builder.query({
query:()=>{
return{
url:`/api/orders/myorders`,
method:'GET',
provideTags:['Refetchorders']
}
}
)}
)}
因此每当用户点击注销时IAM触发API调用以通过调用getmyorders来重置高速缓存
const[getMyOrders,getMyOrdersResult]=useGetMyOrdersQuery(skipToken);
const logoutHandler=()=>{
getMyOrders()
navigate('/')
}
注销处理程序位于加载主屏幕时加载的标题中,我看到的错误是
Uncaught TypeError: object is not iterable (cannot read property Symbol(Symbol.iterator))
1条答案
按热度按时间dkqlctbz1#
在这里,您使用
useGetMyOrdersQuery
就像使用useGetMyOrdersLazyQuery
一样。正确的用法是
或
当您触发查询时,您直接从该站点导航离开,我会问您是否需要其中的任何一个。获取下一个站点所需的数据应该是下一个站点的责任,而不是您正在导航离开的站点的责任。