Nuxt/examples/use-cookie/app.vue
2021-11-22 23:50:17 +01:00

31 lines
575 B
Vue

<script setup>
const user = useCookie('user')
const logins = useCookie('logins')
const login = () => {
logins.value = (logins.value || 0) + 1
user.value = { name: 'CookieLover.' + new Date().getMilliseconds() }
}
const logout = () => {
user.value = null
}
</script>
<template>
<div v-if="user">
<h1>Welcome {{ user.name }}</h1>
<button @click="logout">
logout
</button>
<hr>
You have logged in {{ logins }} times!
</div>
<div v-else>
Click here to login:
<button @click="login">
Login
</button>
</div>
</template>