I am writing an app with vuejs and I want to load data when component is mounted but setup returns data before onMounted loads data
My Code I got the id from another component through props. then passed it through a function which contains an axios method.
The returns an array of data.
export default defineComponent({
props: {
courseId: {
type: String
}
},
data(){
return {
courseDetails: []
}
},
setup(props) {
let courseDetail = reactive([])
let sections = reactive([])
console.log("No details", courseDetail)
onMounted(() => {
// showLoader(true);
Course.getSectionAndSubsections("get-section-and-subsections", props.courseId).then(response => {
courseDetail = response.data.courses;
sections = response.data.sections;
console.log("leave my house", courseDetail)
NotificationService.success(response.data.message);
// showLoader(false);
}).catch(err => {
NotificationService.error(err.response);
// showLoader(false);
});
});
console.log("Course detail ", courseDetail);
return{
courseDetail
}
}
})
How can I solve this problem?