I'm trying to show the card info of South Africa as default value (before typing any country's name into the search bar input field or chosing a specific country out of a given list) and the according country info details within the card container! In this context, I'm using the restcountries api with their country json info! Why is it not working with 'forEach' and maybe you might have any ideas or suggestions how to solve it?
beforeMount() {
var self = this;
var found = false;
this.countries.forEach(function(element) {
if(element['alpha2Code'] === 'ZA') {
self.selectCountry(element);
//self.push(element);
found = true;
}
});
if(!found)
this.selectCountry(this.countries[0]);
},
html:
<main>
<nav>
<div id="app">
<div class="country-search">
<input type="text" placeholder="Search country..." autocomplete="off" v-model="search">
</div>
<div class="country-list" id="country-list">
<div class="country" v-for="(country, index) in countries" method="GET" @click="selectCountry(country)">
<img :src="getFlagSrc(country)">
{{ getName(country).common }}
</div>
</div>
</nav>
<section :style="{ 'background-image': url(' + selectedFlagSrc + ')' }" v-for="(country, index) in filteredCountries" @click="selectCountry(index)">
<div class="card-container">
<div class="card">
<div class="card-title">
<img :src="selectedFlagSrc.flags.png" alt="" />
{{ selectedName.common }}
</div>
<div class="card-body">
<div><strong>Code: </strong>{{ selectedCode }}</div>
<div><strong>Capital: </strong>{{ selectedCapital }}</div>
<div><strong>Region: </strong>{{ selectedSubregion }}</div>
<div><strong>Language: </strong>{{ selectedLanguage }}</div>
<div><strong>Currency: </strong>{{ selectedCurrency }}</div>
<div><strong>Timezone: </strong>{{ selectedTimezone }}</div>
<div><strong>Population: </strong>{{ selectedPopulation }}</div>
<div><strong>Area: </strong>{{ selectedArea }}</div>
<div><strong>World Bank Gini: </strong>{{ selectedGini }}</div>
<div><strong>Lat Long: </strong><a :href="selectedLatlngUrl" target="_blank">{{ selectedLatlng }}</a></div>
</div>
</div>
</div>
</section>
</main>
I hope to solve the issue with the default values!All around the card container on the right one should see the flag of South Africa as default bfore making any choice (respectively afterwards - the given flag of a chosen or country typed into the input field on the left in the picture below)! So far, the info concerning the chosen country haven't been correctly transferred to the card container on the right, unfortunately ;(!
So far, I've managed to solve the background topic, the one with the card container title repetition and could also return the vast majority of the card container values (with a mix of your and my code parts), except for the currencies and languages which are definitely more challenging in the v3.1 of restcountries api and I've to think about in more detail now Well, default value of South Africa (beforeMount) and the geodata info for currencies and languages are still missing and to elaborate on!
If anyone of the brain drain here had any suggestions or ideas how to cope with the remaining parts, I'd be more than grateful for any hints ;)!
For those of you who continuously like to train their brain and solve challenging tasks, I hereby provide you with my updated code (see codepen-link below )! As I'm well aware of the fact that it is by far not perfect I'm doing my best to improve and further elaborate on it !