integración dinamica componentes y json con idioma
This commit is contained in:
21
components/HeroHome.vue
Normal file
21
components/HeroHome.vue
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<h1>{{ title }}</h1>
|
||||||
|
<h2>{{ subtitle }}</h2>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
subtitle: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -1,4 +1,9 @@
|
|||||||
|
[
|
||||||
{
|
{
|
||||||
"title": "Benvingut",
|
"component": "HeroHome",
|
||||||
"body": "Aquest és el contingut en català."
|
"props": {
|
||||||
|
"title": "Benvingut al Kit",
|
||||||
|
"subtitle": "Tot per a l'economia social"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -1,4 +1,9 @@
|
|||||||
|
[
|
||||||
{
|
{
|
||||||
"title": "Bienvenido",
|
"component": "HeroHome",
|
||||||
"body": "Este es el contenido en español."
|
"props": {
|
||||||
|
"title": "Bienvenido al Kit",
|
||||||
|
"subtitle": "Todo para la economía social"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|||||||
@@ -1,24 +1,29 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<main v-if="landingComponents" class="min-h-screen relative">
|
||||||
<div>
|
<template v-for="(component, index) in landingComponents" :key="`component-${component.component}-${index}`">
|
||||||
<h1>{{ content.title }}</h1>
|
<component
|
||||||
<p>{{ content.body }}</p>
|
:is="component.component"
|
||||||
</div>
|
v-if="component"
|
||||||
|
v-bind="component.props" />
|
||||||
<p>Idioma actual: {{ $store.getters['langcode'] }}</p>
|
</template>
|
||||||
<p>Ruta actual: {{ $route.params.langcode }}</p>
|
<!-- <div class="fixed bottom-0 right-0 z-50 p-2">
|
||||||
<button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" @click="cambiarIdioma">
|
<ButtonCTA @click="changeLang" >
|
||||||
{{ $store.getters['langcode'] === 'es' ? 'Cambiar a Català' : 'Canviar a espanyol' }}
|
Cambiar Idioma
|
||||||
</button>
|
</ButtonCTA>
|
||||||
</div>
|
</div> -->
|
||||||
|
</main>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapGetters, mapActions } from 'vuex';
|
import { mapGetters, mapActions } from 'vuex';
|
||||||
|
import HeroHome from '~/components/HeroHome.vue';
|
||||||
export default {
|
export default {
|
||||||
|
components: {
|
||||||
|
HeroHome,
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
content: {},
|
landingComponents: []
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -28,26 +33,26 @@ export default {
|
|||||||
const langcode = this.$route.params.langcode;
|
const langcode = this.$route.params.langcode;
|
||||||
try {
|
try {
|
||||||
const res = await import(`~/data/${langcode}/index.json`);
|
const res = await import(`~/data/${langcode}/index.json`);
|
||||||
this.content = res.default;
|
this.landingComponents = res.default;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error al cargar contenido:', err);
|
console.error('Error al cargar contenido:', err);
|
||||||
this.content = {
|
this.landingComponents = [
|
||||||
title: 'Contenido no disponible',
|
{
|
||||||
body: 'No se pudo cargar el contenido.',
|
component: 'ErrorComponent',
|
||||||
};
|
props: {
|
||||||
|
message: 'Contenido no disponible',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions(['setLangcode']),
|
...mapActions(['setLangcode']),
|
||||||
cambiarIdioma() {
|
// changeLang() {
|
||||||
const nuevoIdioma = this.langcode === 'es' ? 'cat' : 'es';
|
// const newLang = this.langcode === 'es' ? 'cat' : 'es';
|
||||||
this.setLangcode(nuevoIdioma);
|
// this.setLangcode(newLang);
|
||||||
this.$router.push({ path: `/${nuevoIdioma}` });
|
// this.$router.push({ path: `/${newLang}` });
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
|
|
||||||
</style>
|
|
||||||
Reference in New Issue
Block a user