I'm trying to load page contents using Vue JS
. Interface is simple with one select
, one textarea
and one button
. I'm trying to load all the contents from third party api response. First element get loaded fine, but the items that are being tried to load after don't work at all unless typed something inside the textarea
. Situation is similar to this post. But in my case there are multiple iterations of loop from which I'm trying to load data.
So.
HTML
<div class="col-md-12 offset-s-1">
<ul>
<li v-for="title in titles">
<div class="row">
<div class="col-md-6">@{{ title.name }}</div>
<div class="col-md-6">@{{ title.status }}</div>
<div class="col-md-12">@{{ title.date }}</div>
<div class="col-md-12">@{{ title.desc }}</div>
</div>
<ul>
<li v-for="show in title.shows">
@{{ show.title }}
<ul>
<li v-for="episode in show.episodes">
<div class="col-md-12">@{{ episode.title }}</div>
<div class="col-md-12" v-html="episode.status"><b>Episode Status</b>: @{{ episode.status }}</div>
<div class="col-md-12"><b>Episode Update Date</b>: @{{ episode.date }}</div>
<div class="col-md-12"><b>Episode Description</b>: @{{ episode.desc }}</div>
<div class="col-md-12"><b>Episode Release Year</b>: @{{ episode.year }}</div>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
JS:
response.seasons.forEach(function (season, seasonIndex) {
axios.get('api requested uri').then(function (season) {
self.titles[index].shows[seasonIndex].episodes = season.data.episodes;
season.data.episodes.forEach(function (episode, episodeIndex) {
axios.get('api requested uri').then(function (episodes) {
episodes.data.show_id = show.data.id;
self.saveEpisode(episodes.data, index, seasonIndex, episodeIndex);
}).catch(function (error) {
console.log(error);
});
});
}).catch(function (error) {
console.log(error);
});
});
saveEpisode: function (data, index, seasonIndex, episodeIndex) {
var self = this;
axios.post(baseUrl + 'save-episode', data).then(function (response) {
self.titles[index].shows[seasonIndex].episodes[episodeIndex].status = response.data.status;
self.titles[index].shows[seasonIndex].episodes[episodeIndex].date = response.data.date;
self.titles[index].shows[seasonIndex].episodes[episodeIndex].year = response.data.year;
self.titles[index].shows[seasonIndex].episodes[episodeIndex].desc = response.data.desc;
}).catch(function (error) {
console.log(error);
});
}
Response coming from first request being rendered fine, but after that nothing happens. How this can be control with Vue JS
. Should I create HTML
snippets and append those to div
as I receive response from API or is there any other way to achieve this?
data
declaration.
data: {
title: null,
titles: [],
type: 'movie'
}
First request is simple ajax
request and it passes response data into function, there it's being set.
self.titles[index].shows = response.seasons;
self.titles[index].date = show.data.date;
self.titles[index].desc = show.data.desc;
Thanks.