Issue with displaying V-For elements in Bootstrap Dropdown Button

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?

Answer №1

I found a solution by transferring the v-for syntax to a template

Instead of the previous code snippet:

<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>

You can do this instead:

<div class="dropdown-menu" aria-labelledby="languageDropdown">
  <template v-for="(value, key) in languages" v-bind:key="key">
    <a class="dropdown-item" href="#" @click="changeLanguage(key)">{{ value }}</a>
  </template>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Video with dynamic sizing doesn't adapt properly

I successfully achieved my main goal, which was to have a background video at the top of my page. However, I am facing an issue with making the video responsive. Currently, as I decrease the screen size, the video shrinks in both width and height rather th ...

Unique column arrangement specifically designed for the initial row within the loop

My webpage features a layout that showcases 4 images on each row. However, I am looking to create a special first row with a unique column configuration compared to the rest of the rows. Here is an example of what I have in mind: https://i.sstatic.net/Rs ...

Can a function be called when using ng-options with AngularJS select?

Here is some HTML code <select ng-model="selectedMarker" ng-options="shape.text for shape in Selects('shapes')"> </select> And below is the JavaScript code angular.module('todo', ['ionic']) . ...

Buttons for concealment and revelation are unresponsive

I have the following code snippet for uploading an image, which is taken from a template utilizing bootstrap 2. <div class="span6"> <div class="control-group"> <label class="control-label">Imagen</label> <div cla ...

Is it possible to utilize context within a custom hook?

Here is a custom hook that attempts to use context inside it, but results in an error stating "Invalid hook call. Hooks can only be called inside of the body of a function component" export const useFetch = async () => { const { city, setFetchError } = ...

Display information retrieved from a PHP request on an AngularJS webpage

I could really use some assistance upfront! I am facing issues with displaying the data retrieved from PHP on an AngularJS website. I have reviewed previous discussions on this topic, but unfortunately, none of them have proven helpful. From what I can te ...

"Embed" three.js within SmartMS

Is it possible to incorporate this simple three.js example into Smart Mobile Studio without extensive wrapping? I attempted to copy the window.onload content into an asm section but was unsuccessful. <!DOCTYPE html> <html> <head> <t ...

PHP is unable to render Google Maps on the webpage

My PHP code retrieves location information from a database (test) and table named manu, created using phpmyadmin in Wamp. It then displays those locations on a map with markers, showing latitude and longitude values. UPDATED <? $dbname =&ap ...

Significant slowdown observed when deleting multiple objects from the Three.js scene

We are facing a challenge when dealing with large Three.js scenes that consist of many individual objects. In some cases, our scenes can contain anywhere from 25,000 to 50,000 instances of Object3D. While this may seem like a lot, we haven't found an ...

Automating Internet Explorer using VBA to click a button

I'm currently working on automating tasks on a website using VBA, specifically an online banking system where I am trying to export Transaction History data into a .csv file. Everything seems to be running smoothly until I reach the final Export butto ...

Show the present category name within breadcrumbs (utilizing angularJS)

Struggling to display category and vendor names on breadcrumbs? Utilizing the ng-breadcrumbs module but encountering difficulties in making curCategory and curVendor globally accessible. Tried various methods without success. Below is the HTML code snippe ...

Reactive behavior is not present in Vuex getters when working with normalized data

After normalizing my data in a Vuex application, I encountered an issue with watching for changes in the data. Let me explain my setup using a simplified version. State: const state = { shapes: { collection: [1, 2, 3], data: { ...

AngularJS - Setting an initial delay for ng-bind

We have a span element with the following attributes: <span role="link" ng-show="showLink()" ng-bind="textLink"></span> (Just an fyi: we implemented a fade-in, fade-out animation for this link, hence the use of ng-show instead of ng-if) The ...

Bootstrap 4 collapsible navbar with a stacked design

I am struggling to create a collapsible navbar. Even though everything seems to be working, the nav items are not stacking vertically as they should be. Instead, they are appearing horizontally next to each other. Here is the code snippet: <nav class= ...

Concealing JSON Parsing Errors during Express POST Requests

Here is a snippet of my Express server: var express = require("express"); var app = express(); app.use(express.json()); app.post("/hackme", (req, res) => { if(!req.body.foo) { return res.send({ error: 'oh no' }); } ret ...

Link the selector and assign it with its specific value

Greetings, I am a newcomer to React Native and I am currently using Native Base to develop a mobile application. I am in the process of creating a reservation page where I need to implement two Picker components displaying the current day and the next one ...

Tips for accessing the HTML content enclosed within a specific HTML tag using Python with Selenium

I am trying to extract the source code of an HTML document that is embedded within an <iframe> tag generated by JavaScript. The HTML contents within this <iframe> tag appears as #document, which expands to reveal a full HTML document starting w ...

Using Vue.js to update a variable in a parent component that is nested multiple layers deep

Check out my cool Vue Instance: const myApp = new Vue({ el: '#my-app', data() { return { trigger: true } }, components: { ChildComponentOne, ChildComponentTwo }, router, store, ...

Is the card-columns class not available in Bootstrap 5.0? Are there any other alternatives provided by Bootstrap besides using CSS media queries and flex column?

While exploring Bootstrap 5.0, I noticed that the card-columns class was missing and there is no mention of it or its alternative in the Bootstrap 5.0 documentation. However, it can still be found in the Bootstrap 4.6 documentation. I understand that usin ...

Show JSON array items

My php file (history.php) generates a JSON object $i=1; $q=mysql_query("select * from participants where phone='".mysql_real_escape_string($_GET['phone'])."' limit 10"); while($rs=mysql_fetch_array($q)){ $response[$i] = $rs[&ap ...