Can anyone help me with this question noted in the title? How can I prevent a component from mounting in <router-view>
until it receives data from the server, or how can I fetch the data before the component is mounted in <router-view>
?
Here are my files:
1st main.js
new Vue({
el: '#app',
router,
components: { Login, Start },
data: function(){
return{
info: null,
}
},
methods:{
bef:function(){
this.$http.get('xxx').then(function(response){
return response.body
});
}
},
beforeMount(){
this.info = this.bef()
}
})
2nd component file Comp.vue
export default {
name: 'start',
data(){
return{
}
},
beforeMount(){
console.log(this.$parent.info)
}
}
How can I properly ensure that I get a non-null value, but rather a response from the server?
Thank you for your help.