I am facing an issue with a component where I need to fetch data using an ajax call. The component is being called correctly and the data is returned in the ajax call, but I am struggling to assign it to the data in the template?
<template>
<div class="class-hero" id="dashboard-hero" :style="{ 'background-image': 'url(' + last.content_image + ')' }">
<div class="class-hero-overlay"></div>
<div class="class-hero-container">
<h1> {{ last.content_name }}</h1>
<p> {{ last.content_description }} </p>
<div class="class-stat">
<div id="classesCirle" class="hero-class-progress"></div>
<p>Modules</p>
</div>
<div class="class-stat">
<div id="studentsCircle" class="hero-class-progress"></div>
<p>students</p>
</div>
<div class="class-stat">
<div id="tasksCirle" class="hero-class-progress"></div>
<p>tasks</p>
</div>
<a :href="'/all-classes/' + last.content_name + '/' " class="button-resume"><p>Resume</p></a>
</div>
</div>
</template>
<script>
module.exports = {
data: function() {
return {
last:[]
}
},
mounted: function() {
axios.get('/custom_api/api_home_get.php?', {
params: {
ID: 14
}
})
.then(function (response) {
this.last = response.data.currentCourses[0];
console.log(response.data.currentCourses[0]);
})
.catch(function (error) {
console.log(error);
});
}
}
</script>
I'm wondering if this is something that can be achieved. How can I properly set the data last
from the ajax call within the mounted
method?