0

I have a country.vue component.

I'm doing a loop for. And in this loop, I'd like to collect only the country names based on the locale of the application.

To collect the locale, I create a new data called "local". I would like to combine this locale in my :label.

<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 would like to do something like this:

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

Thanks for your help

3
  • 2
    Did you try country.translations[locale]? Commented Jun 25, 2018 at 16:36
  • 1
    @mhodges I did not know, but it works! It has a name? Thanks a lot for your help ! Commented Jun 25, 2018 at 16:42
  • Just posted an answer with a link to more details. Glad that worked for you :) Commented Jun 25, 2018 at 16:47

1 Answer 1

4

You can use JavaScript's built-in Bracket Notation Property Accessor to accomplish this, like so:

<el-option
    v-for="country in countries"
    :key="country.name"
    :value="country.name"
    :label="country.translations[locale]">
</el-option>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.