How can I efficiently load the authenticated user and access it across all my Vue components without making unnecessary AJAX requests, as I can directly fetch it from the back-end?
In my Laravel home.blade.php
file, I have a reference to a Vue
app and attempted to bind the Auth::user()
directly to the main Vue instance:
<div id="app" :authuser="{{ Auth::user() ? : '[]' }}"></div>
The content of my app.js file is as follows:
const app = new Vue({
el: '#app',
props: ['authuser'],
data: { authuser: this.authuser }
});
However, it appears that passing props directly to the main Vue
object may not work. What would be the most effective approach to achieve this?
Please note: Any suggestions aside from using props are welcome. Ideally, I aim to create a global reference to an authuser
object that can be accessed by all Vue components. For instance, could this be achieved through window.authuser
?