1

I have to yml files (one in Fr and another in Nl), each with a line called "language", with the respective language.

Let's say that I'm receiving from the back a list in both languages of words, I save them as listFr & listNl.

And what I want to do is a dynamic v-for loop, using the variable language mentioned above, maybe something like this

         <ul>
          <li
            v-for="(list, index) in `list${$t('language')}`"
            :key="index"
          >
            <p class="element-title">{{ list.title }}</p>
          </li>
        </ul>

But obviously this is not correct as it's not showing the list of words. Thanks for your help!

1 Answer 1

2

I think this is the best way

<template>
    <ul>
        <li v-for="(list, index) in dynamicList" :key="index">
            <p class="element-title">{{ list.title }}</p>
        </li>
    </ul>
</template>

<script>
export default {
    data() {
        return {
            listFr: [],
            listNi: [],
        }
    },
    computed: {
        dynamicList() {
            return this["list" + this.$t('language')]
        }
    }
};
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

Don't use index as the key tho.

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.