Upon initializing my vue.js 2.0 application, I create a window.User
object.
Everything seems to be functioning correctly. However, I encounter an issue when trying to use it in some components within my templates:
v-if="this.User.role == 2"
In some components, this works perfectly fine while in others it throws an error (
Cannot read property 'role' of undefined
). How is this even possible? To troubleshoot, I attempted the following in the problematic components:
created() {
alert(window.User.role);
}
Surprisingly, the expected result appears! But for some reason, it doesn't work within the template. What could be causing this discrepancy? It's quite frustrating.
In my bootstrap.js:
window.User = Laravel.user;
I register all my components in a similar manner:
Vue.component('corporations', require('./components/corporation/Corporations.vue'));