Skip to content

怎么重置数据data呢? #257

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

Open
latel opened this issue Apr 11, 2025 · 4 comments
Open

怎么重置数据data呢? #257

latel opened this issue Apr 11, 2025 · 4 comments
Labels
question Further information is requested

Comments

@latel
Copy link

latel commented Apr 11, 2025

问题描述 Problem Description

我一个页面参数会变,参数变化后需要重新请求,且确保旧的数据要清空,目前我这样做,总是报类型错误

const { data, error, loading, run, cancel, mutate } = useRequest(GetMarketStatusBinding, {
  defaultParams: [
    {
      market: 1,
      accountId: '',
    },
  ],
});

const reset = () => {
  mutate([])
};

Image

@latel latel added the question Further information is requested label Apr 11, 2025
@latel
Copy link
Author

latel commented Apr 11, 2025

我也不想用as :sad

@latel
Copy link
Author

latel commented Apr 11, 2025

Image

@John60676
Copy link
Member

重新请求让新数据覆盖旧的数据不就可以了吗。如果你是要实现“清空”,我建议data套一层computed,通过computed实现你想要的功能

@latel
Copy link
Author

latel commented Apr 17, 2025

@John60676 同一个页面复用,只是query变化的情况下,有时候不想保留上一个请求的旧数据,需要重新请求前清空旧的数据。

既然data初始时就是undefined,我觉得不如mutate函数的入参类型允许undefined类型 @AttoJS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants