Right now, I have an application where a modal pops up when a user logs in. Just a generic welcome message, but I am not sure if I am satisfied with the method I am using. Right now I am calling the modal using a beforeRouteEnter, which triggers a boolean that opens the modal. It works, but I notice that this triggers the modal before axios has been able to fetch my user data, which means that the modal first shows up with no data and then 2-3 seconds after the data gets loaded into it.
Is there any other way I can trigger this modal when a user logs in without using beforeRouteEnter? Or is there a way to somehow get the data from Axios faster?
My parent:
<template>
<b-container class="my-4">
<welcome-modal :show-modal="visible" />
</b-container>
</template>
<script>
import WelcomeModal from '@/views/company/WelcomeModal';
export default {
components: {
WelcomeModal
},
data() {
return {
visible: false,
};
},
beforeRouteEnter(to, from, next) {
next((vm) => {
if (from.path === "/login") {
vm.visible = true;
}
});
},
}
};
</script>
The child/modal:
<template>
<b-modal
:modal-class="modalStyling"
centered
modal-class="justify-content-center"
v-model="isVisible">
<b-row v-for="user in user">
<b-col class="text-center">
<h2>{{ 'welcome' + ' ' }} {{ user.name }}</h2>
</b-col>
</b-row>
</b-modal>
</template>
<script>
import {axiosService} from '@/services/axios';
export default {
props: {
showModal: Boolean
},
data() {
return {
isVisible: false,
logs: {},
currentUser: [],
user: {},
};
},
methods: {
getUser(){
axiosService.getCurrentUser()
.then(result => {
this.user = result.data;
return axiosService.getUserLogs(this.user.id)
.then(result => this.logs = result.data);
})
}
},
created(){
this.getUser()
this.isVisible = this.showModal
},
};
</script>