-
Notifications
You must be signed in to change notification settings - Fork 97
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
轮询时,如何只loading一次?后面的请求不再loading 了 #213
Comments
+1,现在要实现这种需求还得自己手动维护一个参数,如果官方能提供参数控制就最好了 |
针对这个建议,可以考虑通过自定义一个插件去实现。不过轮询次数的统计返回值,可以考虑实现。 |
我的建议是 自己维护一个 loading 的 ref,在点击的时候设置为 true, 在 onsuccess 中判断,如果 loading 为 true 则设置为 false. |
可以这样 v-loading="loading && !data",其实更希望内部抛出一个 refreshing。 |
@zm8 可以通过插件式去实现这种定制需求 https://inhiblabcore.github.io/docs/hooks/useRequest/plugin/ 。也可以参考官方的插件进行设计实现 |
@zaxlct @zm8 @XiaoDaiGua-Ray 这也是一个好的方式。我这里只写了个 demo,具体细节可以在业务中再完善哈。插件系统搞起来 🤩 const useFirstLoadingForPollingPlugin: UseRequestPlugin<
any,
[],
{
usePollingFirstLoading?: boolean
pollingCallback?: (isLoading: boolean) => void
}
> = (fetchInstance, { pluginOptions }) => {
const usePollingFirstLoading = !!pluginOptions?.usePollingFirstLoading
const markRef = ref(false)
return {
name: 'firstLoadingForPollingPlugin',
onBefore: () => {
if (usePollingFirstLoading && !markRef.value) {
markRef.value = true
pluginOptions?.pollingCallback(true)
} else {
pluginOptions?.pollingCallback(false)
}
},
onSuccess: () => {},
}
}
const isLoadingRef = ref(false)
const { data, loading } = useRequest(
() => getUsername(),
{
debugKey: 'plugindemo',
pollingInterval: 2000,
pluginOptions: {
usePollingFirstLoading: true,
pollingCallback: isLoading => {
console.log('isLoading', isLoading)
isLoadingRef.value = isLoading
}
},
},
[useFirstLoadingForPollingPlugin],
) |
Description
如果页面上绑定了
v-loading="loading"
那么每次请求都会loading一次,我的需求是只希望第一次时loading,后续不要再loading了,这样会打断用户操作Suggested solution
建议:返回一个类似
pollingTimes
的参数?如果是1就代表执行了一次Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: