Take a look at my Vue.js (3) component, styled with Bootstrap (5):
<template>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle btn-link text-decoration-none text-dark" type="button" id="languageDropdown" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ languages[$i18n.locale] }}
</button>
<div class="dropdown-menu" aria-labelledby="languageDropdown" v-for="(value, key) in languages" v-bind:key="key">
<a class="dropdown-item" href="#" @click="changeLanguage(key)">{{ value }}</a>
</div>
<li v-for="(value, key) in languages" v-bind:key="key">
{{ key }}: {{ value }}
</li>
</div>
</template>
<script>
export default {
name: "LanguageSwitcher",
data() {
return {
languages: {
'en': 'English',
'de': 'Deutsch',
}
};
},
methods: {
changeLanguage: function(lang){
this.$i18n.locale = lang;
}
}
};
</script>
When I add the v-for
, only the first element from the languages
object appears. Any idea why?
The list displays both languages correctly.
https://i.sstatic.net/irUQX.png
In the dropdown, however, "Deutsch" is missing.
https://i.sstatic.net/hlWtX.png
Could this be a Bootstrap/Vue issue, or am I overlooking something here?