0👍
It is not a redundancy problem, it’s a logic problem. You should not pass ANY variable from blade to view in my opinion. You should do something like this:
- Your controller (maybe from the index method) checks if the request wants a JSON response, if not returns the view, otherwise the collection as a JSON response (go on to understand why).
- When the view is loaded, VueJs loads the component and (this is how I do it) within the
mounted
method you make an Ajax call (maybe with axios) to your controller which will return the collection
In this way you have an asynchronous request management, that will allow you to refresh the data, and avoid to reload the page each time.
As I wrote before, I would avoid as much as possible to pass properties from blade to vue, unless they’re context variables like user preferences or system settings.
-2👍
Your code is ok. You can get categories over ajax. In your case, it is not recommended to use ajax.
- [Vuejs]-Vuex- dynamic modules don't have unique data
- [Vuejs]-How to run js code before everything in the page? I have session check in js and it should redirect to another page
Source:stackexchange.com