2024-07-18 14:52:40 +00:00
|
|
|
<script setup lang="ts">
|
2023-05-26 19:42:12 +00:00
|
|
|
useCookie('accessed-but-not-used')
|
2024-07-18 14:52:40 +00:00
|
|
|
useCookie('accessed-with-default-value', { default: () => 'default' })
|
2023-05-26 19:42:12 +00:00
|
|
|
useCookie('set').value = 'set'
|
|
|
|
useCookie('set-to-null').value = null
|
2024-07-18 14:52:40 +00:00
|
|
|
useCookie<string | null>('set-to-null-with-default', { default: () => 'default' }).value = null
|
2024-01-29 10:37:32 +00:00
|
|
|
|
2023-05-26 19:42:12 +00:00
|
|
|
// the next set are all sent by browser
|
|
|
|
useCookie('browser-accessed-but-not-used')
|
2024-07-18 14:52:40 +00:00
|
|
|
useCookie('browser-accessed-with-default-value', { default: () => 'default' })
|
2023-05-26 19:42:12 +00:00
|
|
|
useCookie('browser-set').value = 'set'
|
2024-07-18 21:03:50 +00:00
|
|
|
// confirm that it only sets one `set-cookie` header
|
|
|
|
useCookie('browser-set').value = 'set'
|
2023-05-26 19:42:12 +00:00
|
|
|
useCookie('browser-set-to-null').value = null
|
2024-07-18 14:52:40 +00:00
|
|
|
useCookie<string | null>('browser-set-to-null-with-default', { default: () => 'default' }).value = null
|
2024-01-02 15:37:19 +00:00
|
|
|
|
2024-07-18 14:52:40 +00:00
|
|
|
const objectCookie = useCookie<{ foo: string } | undefined>('browser-object-default')
|
2024-02-03 23:15:26 +00:00
|
|
|
const objectCookieSecond = useCookie('browser-object-default', {
|
2024-04-05 18:08:32 +00:00
|
|
|
default: () => ({ foo: 'bar' }),
|
2024-01-02 15:37:19 +00:00
|
|
|
})
|
2024-07-18 14:52:40 +00:00
|
|
|
function changeCookie () {
|
|
|
|
if (objectCookie.value!.foo === 'baz') {
|
|
|
|
objectCookie.value!.foo = 'bar'
|
|
|
|
} else {
|
|
|
|
objectCookie.value!.foo = 'baz'
|
|
|
|
}
|
|
|
|
}
|
2023-05-26 19:42:12 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<div>cookies testing page</div>
|
2024-07-18 14:52:40 +00:00
|
|
|
<pre>{{ objectCookie?.foo }}</pre>
|
2024-02-03 23:15:26 +00:00
|
|
|
<pre>{{ objectCookieSecond.foo }}</pre>
|
2024-07-18 14:52:40 +00:00
|
|
|
<button @click="changeCookie">
|
2024-01-02 15:37:19 +00:00
|
|
|
Change cookie
|
|
|
|
</button>
|
2024-02-03 23:15:26 +00:00
|
|
|
<button @click="refreshCookie('browser-object-default')">
|
2024-01-29 10:37:32 +00:00
|
|
|
Refresh cookie
|
|
|
|
</button>
|
2023-05-26 19:42:12 +00:00
|
|
|
</div>
|
|
|
|
</template>
|