[Vuejs]-How to load the store in vue when the app first loads

1👍

If you want to load the products once the app is loaded, you can use the onMounted() hook in the composition API.

https://vuejs.org/api/composition-api-lifecycle.html#onmounted

On the component where you want to load the products:

<script setup>
import { onMounted } from 'vue';
import { useCartStore } from '../stores/storeName.js';
const store = useCartStore()
onMounted(() => {

store.getProducts()
})
</script>

Note: I’m using <script setup> here. But if you’re using the setup() hook you need to manually return the function

https://vuejs.org/api/composition-api-setup.html

Leave a comment