You say that you always retieve the right data, so what is the problem ?
If you need to share this function, you could write it in a service.
https://laracasts.com/discuss/channels/vue/vue-add-a-service-to-the-app-or-component
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
What is the right way to make this function available to export in vue 3?
getAuthUserCart(userId) {
axios.get(route("cart.get", userId)).then((res) => {
this.cartAmount = res.data;
});
},
When I use this function in one of my vue components it works correctly, but once I tried to make this function sharable for others components I could get the res correctly
Here is how I rewtire the fn for export
export function getAuthUserCart(userId) {
axios.get(route("cart.get", userId)).then((res) => {
return res.data
});
}
But when I'm triying to use it in the same component it was earlier I can get the res.data that i'm trying to return
import { getAuthUserCart } from "./GetUserCart";
....
mounted() {
if (this.$page.props.auth.user.autorized) {
this.cartAmount = this.getAuthUserCart(
this.$page.props.auth.user.id
); // here I get only undefined
},
Please or to participate in this conversation.