diff --git a/docs/content/1.docs/3.api/1.composables/use-cookie.md b/docs/content/1.docs/3.api/1.composables/use-cookie.md
index 5d3b9dc57d..304857d09b 100644
--- a/docs/content/1.docs/3.api/1.composables/use-cookie.md
+++ b/docs/content/1.docs/3.api/1.composables/use-cookie.md
@@ -25,16 +25,10 @@ The example below creates a cookie called `counter`. If the cookie doesn't exist
```vue
-
Counter: {{ counter || '-' }}
-
-
-
+
Counter: {{ counter || '-' }}
+
+
+
@@ -138,6 +132,71 @@ be returned as the cookie's value.
Specifies a function that returns the cookie's default value. The function can also return a `Ref`.
+### `watch`
+
+Specifies the `boolean` or `string` value for [watch](https://vuejs.org/api/reactivity-core.html#watch) cookie ref data.
+
+- `true` - Will watch cookie ref data changes and its nested properties. (default)
+- `shallow` - Will watch cookie ref data changes for only top level properties
+- `false` Will not watch cookie ref data changes.
+
+**Example 1:**
+
+```vue
+
+
User score: {{ user?.score }}
+
+
+
+```
+
+**Example 2:**
+
+```vue
+
+
+
List
+
{{ list }}
+
+
+
+
+
+
+```
+
## Handling Cookies in API Routes
You can use `getCookie` and `setCookie` from [`h3`](https://github.com/unjs/h3) package to set cookies in server API routes.
diff --git a/packages/nuxt/src/app/composables/cookie.ts b/packages/nuxt/src/app/composables/cookie.ts
index e2e510cf71..10454caec8 100644
--- a/packages/nuxt/src/app/composables/cookie.ts
+++ b/packages/nuxt/src/app/composables/cookie.ts
@@ -15,12 +15,14 @@ export interface CookieOptions extends _CookieOptions {
decode?(value: string): T
encode?(value: T): string
default?: () => T | Ref
+ watch?: boolean | 'shallow'
}
export interface CookieRef extends Ref {}
const CookieDefaults: CookieOptions = {
path: '/',
+ watch: true,
decode: val => destr(decodeURIComponent(val)),
encode: val => encodeURIComponent(typeof val === 'string' ? val : JSON.stringify(val))
}
@@ -32,7 +34,12 @@ export function useCookie (name: string, _opts?: CookieOptio
const cookie = ref(cookies[name] as any ?? opts.default?.())
if (process.client) {
- watch(cookie, () => { writeClientCookie(name, cookie.value, opts as CookieSerializeOptions) })
+ const callback = () => { writeClientCookie(name, cookie.value, opts as CookieSerializeOptions) }
+ if (opts.watch) {
+ watch(cookie, callback, { deep: opts.watch !== 'shallow' })
+ } else {
+ callback()
+ }
} else if (process.server) {
const nuxtApp = useNuxtApp()
const writeFinalCookieValue = () => {