1๐
โ
If you store the languages as an object, like this:
data() {
return {
langs: { en: en, fr: fr }, // or { en, fr } ;)
languageActive: 'en',
}
}
You should be able to key into it like:
<article class="project-card" v-for="item in langs[languageActive].projects"
๐คMatt
1๐
Put your languageActive
in brackets so it will access en
property:
<article class="project-card" v-for="item in [languageActive].projects"
import fr from '../assets/datas/fr.json'
import en from '../assets/datas/en.json'
export default {
data () {
return {
languageActive: 'en',
en: en,
fr: fr,
๐คbill.gates
1๐
You can use ternary operator in your v-for like this:
<div
v-for="(item, index) in languageActive === 'en' ? en.projects : fr.projects"
:key="index">
{{ item }}
</div>
Simple example here: https://codesandbox.io/s/pensive-darkness-bn55w?file=/src/App.vue
๐คOwl
Source:stackexchange.com