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
Source:stackexchange.com