Merging various data sources within a .vue component

In my country.vue component, I am implementing a loop to collect only the names of countries based on the locale of the application.

To retrieve the locale, I have created a new data property called "local". I want to include this locale in my :label attribute.

<template>
<li>
    <el-option
        v-for="country in countries"
        :key="country.name"
        :value="country.name"
        :label="country.translations.fr">
    </el-option>
</li>

<script>
export default {
    data() {
        return {
            countries: [],
            locale: document.querySelector('html').getAttribute('lang')
                }
            },
             …

I am looking for a way to achieve something like this:

<el-option
    v-for="country in countries"
    :key="country.name"
    :value="country.name"
    :label="country.translations.{{locale}}">
</el-option>

Any assistance would be greatly appreciated. Thank you!

Answer №1

To achieve this, you can utilize JavaScript's Bracket Notation Property Accessor feature. Here is an example of how to do it:

<el-option
    v-for="city in cities"
    :key="city.id"
    :value="city.name"
    :label="city.translations[language]">
</el-option>

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

FullCalendar dayClick event fails to trigger any action

I'm having trouble implementing the dayClick function in my fullCalendar. Despite setting up the calendar correctly, nothing happens when I click on a day. Here is the code I am using : var calendar; $(document).ready(function(){ app.init(); ...

Show a pre-made HTML element using the jQuery validation plugin

I am trying to use the jQuery validation plugin to display symbols. When I enter a value incorrectly, the validation error is shown (which is fine) and it should display my custom symbol .validation-incorrect. Once the validation passes, I want to show t ...

Calculating the position of a parallax background within a window

Seeking assistance with what initially seemed like a straightforward task, but has now become quite puzzling. I'm currently working on a basic jQuery script that binds to the window scroll function. Despite seemingly having all the necessary variable ...

What is the process for activating a button after a checkbox has been selected? Additionally, how can a value be dynamically transferred from a checkbox to the rezBlock_1 block?

What could be the reason for my code not functioning properly? How can I enable a button once a checkbox is selected? Also, is there a way to dynamically move text from a checkbox to the rezBlock_1 block? CODPEN https://codepen.io/RJDio/pen/RwPgaaZ doc ...

VueJS: Encounter a hiccup while compiling for production

Having encountered issues while trying to build a production version of my code that previously worked without any problems. Upon running vue build on my main.js file, the following errors are provided: \ Building for production...Browserslist: cani ...

Retrieve the HTML content of all children except for a specific child element in jQuery

Is there a way to utilize jQuery/Javascript for selecting the HTML content of the two <p> elements in the initial <div class="description? I'm open to using Regex as well. This specific jQuery selection is being executed within Node.js on a c ...

Tips for linking two project routes in NodeJS and incorporating React (I am interested in invoking React within the NodeJS project)

I'm in the process of linking two projects, one using reactJS and the other NodeJS. Currently, NodeJS is running smoothly on localhost:3000. Next, I want to call a React application which redirects to port localhost:3001. How can I seamlessly connect ...

Is it possible to trigger an ng-click event while the md-backdrop is present in Angular Material?

In my Angular Material website, a context menu pops up with an md-backdrop whenever the md-menu is shown. Clicking outside the md-menu closes it by triggering the md-backdrop click event. However, I would like to capture that ng-click event. For instance, ...

Custom range-slider in Angular with flexible min/max values

I am currently working with the angular ui-slider and I am looking to dynamically load the min- and max values for the slider from an external source. This will allow me to set them in a structured way, similar to the following: $scope.minMaxValues = { ...

Filtering data at different levels in Javascript/Javascript programming language

Consider this array: var selection = ["14-3","19-5", "23-5", "40-8", "41-8"]; We now have two separate arrays: Array1 includes the first part of each value (before hyphens) in the original array, such as 1 ...

What is the process for conducting a comprehensive match search using dual parameters?

I am working with a database model Schema({ members: [ { type: String, required: true, ref: "User" } ], createdAt: { type: Date, default: Date.now(), required: true }, lastMessage: { message: { typ ...

Issue with Refreshing onRowAdd in React Material Table

I am currently using Material Table to display my table data. However, when I use the onRowAdd function to add a new row, the page does not refresh properly. Instead, it reloads and gets stuck, requiring me to manually refresh again. newData => ...

`How can I use lodash to filter an array based on any matching value?`

I have a collection of objects and I need to search for instances where certain properties match specific values. Here is an example array: let arr = [ { a: 'foo', b: 'bar' }, { a: 'bar', ...

Use bracket notation to verify if a property is undefined

Having some difficulty determining if the property value of an object is undefined when accessed dynamically with bracket notation. Here's a snippet of my code: function toBritishDate(date: Date | string): string { console.log(date) return &qu ...

Store the Ajax response in localStorage and convert it into an object for easy retrieval and manipulation

I'm currently working on an Ajax request that retrieves JSON data from the server and then stores it in localStorage for use in my application. However, I feel like my current code may not be the most efficient way to accomplish this task, as I have t ...

Managing information retrieved from an asynchronous HTTP request

Here is the script I am using to load an HTML page generated by a node.js server: (function nodeLoader(){ $.ajax({ url: "http://oclock.dyndns.org:8000", method: "get", data: {hk: hk }, success: f ...

When loading HTML using JavaScript, the CSS within the HTML is not properly processing. Leveraging Bootstrap 5 might help resolve

Currently utilizing bootstrap 5 for my project. I have a setup in index.html where I am loading the contents of nav.html using JavaScript. However, I am facing an issue wherein the CSS styling for the navbar is not being applied when loaded via JS. Strange ...

I attempted to utilize certain CSS properties, only to find that they were not being applied due to conflicts with Bootstrap's own CSS. I'm unsure what I should do next

click here for image .container, .container-fluid, .container-lg, .container-md, .container-sm, .container-xl, .container-xxl { --bs-gutter-x: 1.5rem; --bs-gutter-y: 0; width: 100%; **padding-right: calc(var(--bs-gutter-x) * .5);** **pa ...

There is a chance that the object could be null. Error code TS2531 occurring in React with TypeScript

I'm currently working on an application using React and TypeScript. However, I encountered an error when trying to use .innerHTML or innerText: An error stating 'Object is possibly null' with the code TS2531 appeared. I am new to TypeScript ...

Problems with script-driven dynamic player loading

I am attempting to load a dynamic player based on the browser being used, such as an ActiveX plugin for Internet Explorer using the object tag and VLC plugin for Firefox and Google Chrome using the embed tag. In order to achieve this, I have included a scr ...