[Vuejs]-V-for with dynamic variable

4👍

You’re almost there: it’s just the square brackets are misplaced + a bit of help with concatenating strings:

 <p>{{ item['name_' + $i18n.locale] }}</p>

However, I am not the biggest fan of in-template string interpolation (personal preference). You can consider offloading/abstracting that logic into a computed property:

computed: {
    i18nameKey() {
        return `name_${this.$i18n.locale}`;
    }
}

Then, you can use i18nameKey in your template as such:

<p>{{ item[i18nameKey] }}</p>
👤Terry

Leave a comment