We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
onFirst
比方说,我希望在第一次返回请求结果时给某个变量赋予一个初始值,我一般使用 vueuse 的一个函数以方便的实现这个效果。
vueuse
const active = ref() const { data } = useRequest(api) watchOnce(data, (res) => { active.value = res[0] })
但大量的这种行为是繁琐的,我想这应该是一个常见的需求,因此希望轮子能自带这方面的支持,api看起来像这样:
const active = ref() useRequest(api, { onFirst: data => { active.value = data[0] } })
let isFirst = true // 假设处理请求的方法叫做execute function execute() { // ... const _onFirst = () => { onFirst() isFirst = false } isFirst && _onFirst() // ... }
无
The text was updated successfully, but these errors were encountered:
你可以自行写一个插件,类似这样的:
export const onFistPlugin = definePlugin((queryInstance, options) => { const isFist = ref(true) return { onSuccess(data) { if (!isFist.value) { return } options.onFirst?.(data) isFist.value = false } } }) --- example --- useRequest(api, { onFirst: data => { active.value = data[0] } }, [onFistPlugin])
Sorry, something went wrong.
No branches or pull requests
需求描述 Feature Description
比方说,我希望在第一次返回请求结果时给某个变量赋予一个初始值,我一般使用
vueuse
的一个函数以方便的实现这个效果。但大量的这种行为是繁琐的,我想这应该是一个常见的需求,因此希望轮子能自带这方面的支持,api看起来像这样:
建议的解决方案 Proposed Solution
其他信息 Other information
无
The text was updated successfully, but these errors were encountered: