Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using useFetch, how to refresh the request with the new body content when the properties within the body change? #15222

Closed
fatcarter opened this issue Oct 21, 2022 · 5 comments
Labels

Comments

@fatcarter
Copy link

fatcarter commented Oct 21, 2022

Nuxt version: 3.0.0-rc.12

const activeOrder = ref("down")
let {data, refresh, execute} = await useFetch<Page<SoftItem>>(`/api/categories/${props.cateKey}/softs`,{
  method: 'post',
  body:  {
    orderBy: activeOrder.value,
    page: 1,
    pageSize: 5
  }
});
const handleChangle = (value)=>{
  activeOrder.value = value;
  refresh();
}

I got old result when call handleChangle function.
How do I refresh the request with the new parameters?

@danielroe
Copy link
Member

This should be resolved in the edge channel, or in the next RC.

You would update your code as follows.

const activeOrder = ref("down")
let {data, refresh, execute} = await useFetch<Page<SoftItem>>(`/api/categories/${props.cateKey}/softs`,{
  method: 'post',
  body:  {
    orderBy: activeOrder,
    page: 1,
    pageSize: 5
  }
});
const handleChangle = (value)=>{
  activeOrder.value = value;
  refresh();
}

Let me know if not and I'll reopen.

@YYCarl
Copy link

YYCarl commented Nov 10, 2022

这应该在边缘通道中解决,或者在下一个 RC 中解决。

您将按如下方式更新您的代码。

const activeOrder = ref("down")
let {data, refresh, execute} = await useFetch<Page<SoftItem>>(`/api/categories/${props.cateKey}/softs`,{
  method: 'post',
  body:  {
    orderBy: activeOrder,
    page: 1,
    pageSize: 5
  }
});
const handleChangle = (value)=>{
  activeOrder.value = value;
  refresh();
}

如果没有,请告诉我,我会重新打开。

How to get new request after "page" parameter is updated

Copy link
Member

See nuxt/framework#8374 (comment).

@YYCarl
Copy link

YYCarl commented Nov 10, 2022

请参阅#8374(评论)

Using is to post the page in the request body, no response

@danielroe
Copy link
Member

@YYCarl You are welcome to open a discussion or post on discord with some code and people can help you debug it :-)

@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants