add pinia

This commit is contained in:
2025-08-04 17:47:09 +02:00
parent ef266dd0ae
commit eb963df89d
5 changed files with 112 additions and 1 deletions

View File

@@ -2,8 +2,22 @@
<v-container
class="fill-height d-flex flex-column align-center justify-center text-center"
>
<img :src="norrisStore.response.icon_url" alt="chuck norris" />
<v-icon icon="mdi-account-box" size="64"></v-icon>
<div class="mt-3">My Application's Contact Page</div>
<div>
{{ norrisStore.response }}
</div>
</v-container>
</template>
<script setup>
import { ref, onMounted } from "vue";
import { useChuckNorris } from "~/stores/chuck";
const norrisStore = useChuckNorris();
onMounted(async () => {
await norrisStore.getData();
console.log(norrisStore.response);
});
</script>

14
app/stores/chuck.js Normal file
View File

@@ -0,0 +1,14 @@
import { defineStore } from "pinia";
export const useChuckNorris = defineStore("chuckNorris", {
state: () => ({
response: "",
}),
actions: {
async getData() {
const response = await fetch("https://api.chucknorris.io/jokes/random");
const data = await response.json();
this.response = data;
},
},
});