I am trying to put {{ $t("xxxxxx") }} in an array inside a Vue component. So that I can create divs with translations and routes dynamically.
The idea is, change this:
const navigation =
[
{
name: "Full Service",
route: "/fullService",
}
]
to this:
const navigation =
[
{
name: {{ $t("fullservice") }},
route: "/fullService",
}
]
I've tried to put like this:
const navigation =
[
{
name: "Full Service",
route: "/fullService",
},
{
name: $t("verkauf"),
route: "/sale",
},
{
name: $t("vermietung"),
route: "/rental",
},
{
name: "Streaming",
route: "/streaming",
},
{
name: "Smart Home",
route: "/smartHome",
},
{
name: $t("kontakt"),
route: "/contact",
},
{
name: $t("impressum"),
route: "/imprint",
},
{
name: $t("cookieRichtline"),
route: "/cookiePolicy",
}
];
<template>
<div v-for="item in navigation" class="
text-mst_white
text-bold
transform
transition
duration-300
hover:text-mst_orange
py-5
px-2
">
<router-link :to="item.route">{{ item.name }}</router-link>
</div>
</template>
I've tried to split the code in diferents parts...create variables, make jsons... But I don't have idea how to do it.
Could anyone help me? Thanks!
When you need
vue-i18n
outside of<template>
in Vue SFCs you need to explicitly import the i18n module in your JS file before using it:Docs: https://vue-i18n.intlify.dev/api/composition#usei18n