clearNuxtState v3.6

删除 useState 的缓存状态。

Maschinelle Übersetzung ·0 % geprüft

此方法在你想使 useState 的状态失效时很有用。你也可以通过传入第二个参数 { reset: true } 来将状态重置为初始值。

类型

Signatur
export function clearNuxtState (keys?: string | string[] | ((key: string) => boolean), opts?: ClearNuxtStateOptions): void

参数

  • keys:在 useState 中使用的一个或多个键,用于删除其缓存状态。如果未提供键,则会使所有状态失效。
  • opts:用于配置清除行为的选项对象。

    • reset v4.4:设为 true 时,会将状态重置为 [useState](/docs/api/composables/use-state) 的 init函数提供的初始值,而不是将其设为undefined。未指定时,默认采用 Nuxt 配置中 experimental.defaults.useState.resetOnClear的值(在compatibilityVersion: 5时为true`)。