Skip to content

Commit

Permalink
chore: update cookie example
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Nov 22, 2021
1 parent a12df69 commit 0db1002
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions examples/use-cookie/app.vue
Original file line number Diff line number Diff line change
@@ -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
</button>
<button @click="counter--">
-
<div v-if="user">
<h1>Welcome {{ user.name }}</h1>
<button @click="logout">
logout
</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>

0 comments on commit 0db1002

Please sign in to comment.