How to use storage globally? #927
-
Hello everyone! Please tell me, I want to create a store and use it in different components.
import { defineStore } from 'pinia';
export const useStore = defineStore('global', {
state: () => ({
//
}),
}); And use them like this
<script setup lang="ts">
import { useStore } from '@/app/stores/global';
const store = useStore();
</script> This creates a new store in each component (which looks logical). But I need shared storage, not separate... |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
The state will be shared globally 🤔. https://pinia.vuejs.org/introduction.html#why-should-i-use-pinia :
<script setup lang="ts">
import { useStore } from '@/app/stores/global';
const store = useStore(); // this store is the same as the store in `Bar.vue`
</script>
<script setup lang="ts">
import { useStore } from '@/app/stores/global';
const store = useStore(); // this store is the same as the store in `Foo.vue`
</script> If you are interested in the underlying technology, please refer to |
Beta Was this translation helpful? Give feedback.
-
Hiho) <script setup>
import {useCartStore} from '../../stores/CartStore'
const store = useCartStore()
</script> I want get acces for |
Beta Was this translation helpful? Give feedback.
The state will be shared globally 🤔.
https://pinia.vuejs.org/introduction.html#why-should-i-use-pinia :
src/component/Foo.vue
src/component/Bar.vue