Skip to content

屏幕聚焦重新请求

通过设置 options.refreshOnWindowFocus 参数,useRequest 会在浏览器窗口重新获得焦点或可见时重新请求。这个功能在用户切换标签页或应用程序后返回时,能确保显示最新的数据。

基础用法

ts
const { data, loading } = useRequest(getUserInfo, {
  refreshOnWindowFocus: true, // 窗口聚焦时刷新
  refocusTimespan: 2000, // 聚焦刷新的时间间隔
});

Options

参数说明类型默认值
refreshOnWindowFocus窗口聚焦时是否自动刷新boolean | Ref<boolean>false
refocusTimespan重新聚焦时间间隔,(毫秒)number | Ref<number>5000

贡献者 ☘️

Flame-00

Flame-00

Creator