Skip to content
On this page

usePolling

一个管理轮询的 Hook

Demo

count: 0
自动轮询

count: 0
手动轮询
<template>
<div>
<Demo1 />
<hr />
<Demo2 />
</div>
</template>

<script setup lang="ts">
import Demo1 from './demo1.vue'
import Demo2 from './demo2.vue'
</script>

Usage

import { usePolling } from 'v3-use'
const { polling, initPolling } = usePolling()
import { usePolling } from 'v3-use'
const { polling, initPolling } = usePolling()

Reference

Type Declarations

export interface Options {
  manual?: boolean
  immediate?: boolean
}
export declare type Polling = Ref<IntervalActions | null>
export declare function usePolling(): {
  polling: Polling
  initPolling: (fn: () => void, interval: number, options?: Options) => void
}
export interface Options {
  manual?: boolean
  immediate?: boolean
}
export declare type Polling = Ref<IntervalActions | null>
export declare function usePolling(): {
  polling: Polling
  initPolling: (fn: () => void, interval: number, options?: Options) => void
}

Params

Result

  • polling: Polling — 轮询控制器
  • initPolling: (fn: () => void, interval: number, options?: Options) => void — 初始化轮询函数