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>
|
|
|
|
|
2021-11-22 20:43:00 +00:00
|
|
|
<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
|
2021-11-22 20:43:00 +00:00
|
|
|
</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
|
2021-11-22 20:43:00 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</template>
|