At my current position we are using Laravel and VueJS and I'm confused/concerned on the design pattern that we are using to integrate the two. I'm hoping to get some advice from the community to see if this is normal. Can't find much info on this design pattern which makes me suspicious it might be an anti pattern.
We are using blade templates to render Vue components, we give those component key props (id's or slugs) so the component can make an api request to the same server to retrieve the necessary data. I find this very confusing because we're not getting any of the benefits from server-side rendering or client side-rendering, right?
blade.php looks like this
<issue-page
issue_id=""
is-admin=""
is-auditor=""
/>
So, inside the issue-page component we will use the issue_id
prop to retrieve the issue from the api when the component mounts. like below.
this.globalRouteMixin("api.quality.issues.show", {
issue: this.issue_id
}).then(route => {
axios
.get(route)
.then(response => {
if (response.status == "200") {
this.issue = response.data.data;
}
this.loading = false;
})
.catch(error => {
console.log(error);
this.loading = false;
});
});
},
Seems very redundant to me.... why doesn't the back-end just pass the whole isssue down, right?
Whats that function globalRouteMixin
you ask?. Well, we are storing all api routes in local storage on the front-end and accessing them via a Vue mixin that takes in a named route as a parameter and returns the url for axios. So the example this.globalRouteMixin("api.quality.issues.show", {issue: this.issue_id})
will return the route /api/quality/issues/3/show
, for example The mixin is responsible for accessing them in local storage, and if the routes are not there (like if someone clears their cache )it will hit an endpoint that retrieves all routes and then stores them. So before every fetch we need to use the globalRouteMixin
to get the correct route. This makes developing very frustrating because any time you deal with routes you have to keep clearing the routes in locastorage to get the latest version.
Is all of this normal?
Aucun commentaire:
Enregistrer un commentaire