I have a one page application that requires authentication. When the user has been authenticated, then go to some pages or click the reload button in the browser, he will ask api to provide his authentication data. then I have this error:
[Vue warn]: Error when evaluating expression "auth.name": TypeError: Cannot read property 'name' of null (found in component: <navbar>)
This error is caused by vue displaying auth data while the api request has not yet completed.
Can vue wait for an api request to complete the first before vue render auth data strong>?
more clearly what is happening here. Here is the code:
// main.js import Vue from 'vue' import App from './App.vue' // root vue import store from './vuex/store' // vuex import router from './router' // my router map sync(store, router) router.start(App, '#app') // end main.js // App.vue <template> <main> <div class="wrapper"> <router-view></router-view> </div> </main> </template> <script> import authService from './services/auth' </script> // end App.vue // SomeRouterComponents.vue <template> <div> // always got error: cannot read property 'name' of null // here I expect to render this after api has been resolved {{ $root.authData.name }} </div> </template>
source share