I have a component that I need to pull some data in through an ajax call. The component is called fine, and the data is returned in the ajax call but I cant 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>
Is this not possible? How can I set the data last
to the ajax call I make in the mounted