有cookies种功能:
很高兴知道:.Set()仅在服务器操作或路由中可用
操控者.
这是Cookies函数:
function cookies() {
if ((0, _staticgenerationbailout.staticGenerationBailout)("cookies", {
link: "https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering"
})) {
return _requestcookies.RequestCookiesAdapter.seal(new _cookies.RequestCookies(new Headers({})));
}
const requestStore = _requestasyncstorage.requestAsyncStorage.getStore();
if (!requestStore) {
throw new Error("Invariant: cookies() expects to have requestAsyncStorage, none available.");
}
const asyncActionStore = _actionasyncstorage.actionAsyncStorage.getStore();
if (asyncActionStore && (asyncActionStore.isAction || asyncActionStore.isAppRoute)) {
// We can't conditionally return different types here based on the context.
// To avoid confusion, we always return the readonly type here.
return requestStore.mutableCookies;
}
return requestStore.cookies;
}`
requestStore.cookies
是RequestCookies
个类实例,即:
declare class RequestCookies {
constructor(requestHeaders: Headers);
[Symbol.iterator](): IterableIterator<[string, RequestCookie]>;
/**
* The amount of cookies received from the client
*/
get size(): number;
get(...args: [name: string] | [RequestCookie]): RequestCookie | undefined;
getAll(...args: [name: string] | [RequestCookie] | []): RequestCookie[];
has(name: string): boolean;
set(...args: [key: string, value: string] | [options: RequestCookie]): this;
/**
* Delete the cookies matching the passed name or names in the request.
*/
delete(
/** Name or names of the cookies to be deleted */
names: string | string[]): boolean | boolean[];
/**
* Delete all the cookies in the cookies in the request.
*/
clear(): this;
toString(): string;
}
如果您想将其设置为中间件,
response.cookies.set(({
name:"foo",
value:"bar",
path:"/"
}))