I have a place for displaying user info, when page refreshed i read user info from an ajax call and set user info data.but because of Time-consuming process of axios call Data setup is performed after the DOM rendering.
HTML :
<div> {{user.name}} </div>
vue.js :
data: function(){
return {
user: {},
}
},
methods: {
getUserInfo() {
axios.post(laroute.route('link'), data).then((response) => {
this.$set(this, 'user', response.data.user);
},
},
mounted() {
this.getUserInfo();
}
after refreshing page i got this error:
"TypeError: Cannot read property 'name' of undefined"
getUserInfo()should undermethods: { getUserInfo() { ... } }response.data.user, maybe isundefined