跳到内容

useMemory

分类
导出大小
533 B
最近更改
3 周前

响应式内存信息。

演示

您的浏览器不支持 performance memory API

用法

ts
import { useMemory } from '@vueuse/core'

const { isSupported, memory } = useMemory()

类型声明

typescript
/**
 * Performance.memory
 *
 * @see https://mdn.org.cn/en-US/docs/Web/API/Performance/memory
 */
export interface MemoryInfo {
  /**
   * The maximum size of the heap, in bytes, that is available to the context.
   */
  readonly jsHeapSizeLimit: number
  /**
   *  The total allocated heap size, in bytes.
   */
  readonly totalJSHeapSize: number
  /**
   * The currently active segment of JS heap, in bytes.
   */
  readonly usedJSHeapSize: number
  [Symbol.toStringTag]: "MemoryInfo"
}
export interface UseMemoryOptions extends UseIntervalFnOptions {
  interval?: number
}
/**
 * Reactive Memory Info.
 *
 * @see https://vueuse.vuejs.ac.cn/useMemory
 * @param options
 */
export declare function useMemory(options?: UseMemoryOptions): {
  isSupported: ComputedRef<boolean>
  memory: Ref<MemoryInfo | undefined, MemoryInfo | undefined>
}
export type UseMemoryReturn = ReturnType<typeof useMemory>

源码

SourceDemoDocs

贡献者

Anthony Fu
Jelf
Anthony Fu
webfansplz

更新日志

v12.0.0-beta.1 于 11/21/2024
0a9ed - feat!: 移除 Vue 2 支持,优化打包并清理代码 (#4349)

根据 MIT 许可证发布。