好吧,我正在使用 wordpress Api,我正在使用 react-query 来重新运行数据。数据显示正常。但是,当我更新 wordpress Api 时,它没有捕捉到更新。如果我想更新浏览器中返回的数据,我必须硬刷新。
const Blog = () => {
const {
isLoading,
data,
isError,
error,
isFetching
} = useQuery(
'blog-post', fetchBlog, {
cacheTime: 5000,
}
)
console.log({
isLoading,
isFetching,
data
});
if (isLoading) {
return <p > Loading < /p>
}
if (isError) {
return <p > {
error.message
} < /p>
}
return ( <
> {
data ? .data.map((item, index) => {
return ( <
div key = {
index
} >
<
img src = {
item._embedded['wp:featuredmedia'][0].source_url
}
alt = 'image1' / >
<
p > {
item.title.rendered
} < /p>
<
/div>
)
})
} <
/>
)
}
我曾尝试使用 isFetching 进行刷新,但它只是返回 false,因此它没有读取更改。我很困。
我也尝试构建使用 axios.get 等的传统路线,但我有同样的问题。