Nuxt/examples/use-cookie/app.vue

31 lines
575 B
Vue
Raw Normal View History

2021-11-22 22:50:17 +00:00
<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>
2021-11-22 22:50:17 +00:00
<div v-if="user">
<h1>Welcome {{ user.name }}</h1>
<button @click="logout">
2021-11-22 23:24:12 +00:00
Logout
</button>
2021-11-22 22:50:17 +00:00
<hr>
You have logged in {{ logins }} times!
</div>
<div v-else>
Click here to login:
<button @click="login">
Login
</button>
</div>
</template>