fix:bug解决
This commit is contained in:
20
src/hooks/use-page-show-refresh.ts
Normal file
20
src/hooks/use-page-show-refresh.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { onShow } from '@dcloudio/uni-app'
|
||||
|
||||
/**
|
||||
* 页面再次显示时执行刷新(从子页返回、切换 Tab 等)。
|
||||
* skipInitialShow:首屏由 onLoad 加载时设为 true,避免与 onLoad 重复请求。
|
||||
*/
|
||||
export function usePageShowRefresh(
|
||||
handler: () => void | Promise<void>,
|
||||
options?: { skipInitialShow?: boolean },
|
||||
) {
|
||||
let skipFirst = Boolean(options?.skipInitialShow)
|
||||
|
||||
onShow(() => {
|
||||
if (skipFirst) {
|
||||
skipFirst = false
|
||||
return
|
||||
}
|
||||
void handler()
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user