Set up pinia
This commit is contained in:
parent
7ac29857ef
commit
160c8a626d
6 changed files with 74 additions and 1 deletions
|
|
@ -1,11 +1,18 @@
|
|||
<script setup lang="ts">
|
||||
import Navbar from "./components/Navbar.vue";
|
||||
import Test from "./components/Test.vue";
|
||||
import { useFooStore } from "./stores/foo";
|
||||
|
||||
const foo = useFooStore();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex h-screen touch-pan-x touch-pan-y flex-col">
|
||||
<Navbar />
|
||||
<div class="h-full overflow-auto">
|
||||
<Test />
|
||||
<br />
|
||||
Yes, it's now {{ foo.name }}.
|
||||
<template v-for="_ in 6">
|
||||
<p class="p-1 font-thin">The quick brown fox Qiii</p>
|
||||
<p class="p-1 font-extralight">The quick brown fox Qiii</p>
|
||||
|
|
|
|||
10
gdn-app/src/components/Test.vue
Normal file
10
gdn-app/src/components/Test.vue
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<script setup lang="ts">
|
||||
import { useFooStore } from "@/stores/foo";
|
||||
|
||||
const foo = useFooStore();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
Foo is {{ foo.name }}.
|
||||
<button @click="foo.setName('bar')">Change to bar.</button>
|
||||
</template>
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import { createPinia } from "pinia";
|
||||
import { createApp } from "vue";
|
||||
import App from "./App.vue";
|
||||
|
||||
createApp(App).mount("#app");
|
||||
createApp(App).use(createPinia()).mount("#app");
|
||||
|
|
|
|||
12
gdn-app/src/stores/foo.ts
Normal file
12
gdn-app/src/stores/foo.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
|
||||
export const useFooStore = defineStore("foo", () => {
|
||||
const name = ref("foo");
|
||||
|
||||
function setName(to: string) {
|
||||
name.value = to;
|
||||
}
|
||||
|
||||
return { name, setName };
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue