如果你想要让 useState 的状态失效,这个方法很有用。你也可以将第二个参数传入 { reset: true },把状态重置为初始值。
:
Signature
export function clearNuxtState (keys?: string | string[] | ((key: string) => boolean), opts?: ClearNuxtStateOptions): void
keys:在 useState 中用于删除其缓存状态的一个或多个 key。如果不提供 key,则所有状态都将被置为失效。opts:一个用于配置清除行为的 options 对象。
reset v4.4:当设为 true 时,将状态重置为 useState 的 init 函数提供的初始值,而不是将其设为 undefined。若未指定,默认为你 Nuxt 配置中 experimental.defaults.useState.resetOnClear 的值(在 compatibilityVersion: 5 下为 true)。