chore: update cookie example

This commit is contained in:
Pooya Parsa 2021-11-22 23:50:17 +01:00
parent a12df69778
commit 0db1002a3b

View File

@ -1,23 +1,30 @@
<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>
<h1> Counter: {{ counter || '-' }}</h1>
<button @click="counter = null">
reset
<div v-if="user">
<h1>Welcome {{ user.name }}</h1>
<button @click="logout">
logout
</button>
<button @click="counter--">
-
</button>
<button @click="counter++">
+
<hr>
You have logged in {{ logins }} times!
</div>
<div v-else>
Click here to login:
<button @click="login">
Login
</button>
</div>
</template>
<script setup>
const counter = useCookie('counter')
counter.value = counter.value || Math.round(Math.random() * 1000)
</script>
<style scoped>
button { margin: 10px 5px; }
</style>