v-for with dynamic variable

I am working on a Vue app with i18n and want to list items from a large JSON file in the selected languages.

Here is an example JSON file:

items: [
    "name_en": "Name",
    "name_de": "Name"
    "year_en": "Year",
    "year_de": "Jahr"

I would like to get the items with v-for like this:

<div v-for="(item, index) in data.items" :key="index">
     <p {{item.name_[$i18n.locale]}} </p>

$i18n.local drops the current language code such as 'en' or 'de'. But what the correct syntax is to get the item.name_en or item.name_de?

Thank you for all your suggestion!

Read more here: https://stackoverflow.com/questions/67932968/v-for-with-dynamic-variable

Content Attribution

This content was originally published by karzol73 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: