跳到主要內容

useThrottledRefHistory

類別
導出大小
1.37 kB
上次變更
5 天前
相關

使用節流過濾器的 useRefHistory 的簡寫。

示範

計數: 0
/
延遲 (毫秒)

歷史紀錄 (示範限制為 10 筆紀錄)
2025-03-10 03:47:04{ value: 0 }

用法

此函式會在計數器的值變更後立即取得第一個快照,第二個快照則延遲 1000 毫秒。

ts
import { useThrottledRefHistory } from '@vueuse/core'
import { shallowRef } from 'vue'

const counter = shallowRef(0)
const { history, undo, redo } = useThrottledRefHistory(counter, { deep: true, throttle: 1000 })

類型宣告

typescript
export type UseThrottledRefHistoryOptions<Raw, Serialized = Raw> = Omit<
  UseRefHistoryOptions<Raw, Serialized>,
  "eventFilter"
> & {
  throttle?: MaybeRef<number>
  trailing?: boolean
}
export type UseThrottledRefHistoryReturn<
  Raw,
  Serialized = Raw,
> = UseRefHistoryReturn<Raw, Serialized>
/**
 * Shorthand for [useRefHistory](https://vueuse.dev.org.tw/useRefHistory) with throttled filter.
 *
 * @see https://vueuse.dev.org.tw/useThrottledRefHistory
 * @param source
 * @param options
 */
export declare function useThrottledRefHistory<Raw, Serialized = Raw>(
  source: Ref<Raw>,
  options?: UseThrottledRefHistoryOptions<Raw, Serialized>,
): UseThrottledRefHistoryReturn<Raw, Serialized>

原始碼

原始碼示範文件

貢獻者

Anthony Fu
Roman Harmyder
IlyaL
Anthony Fu
OrbisK
Jelf
Bodo Graumann
wheat

更新日誌

v12.8.0 於 2025/3/5
7432f - feat(types): 棄用 MaybeRefMaybeRefOrGetter,改用 Vue 原生型別 (#4636)
v12.0.0-beta.1 於 2024/11/21
0a9ed - feat!: 移除 Vue 2 支援,最佳化 bundles 並清理程式碼 (#4349)
v10.7.0 於 2023/12/5
fccf2 - feat: 升級 dependencies (#3614)

在 MIT 許可證下發布。