I'm working on Vue project supporting two languages using VUEX and Vuetify.
Instead of direct referencing the text directly like this:{{ $vuetify.t('$vuetify.my-component.text') }}
, I put it as a state in a namespaced VUEX store module, then reference it as a mapstate computed property like this: {{ textProp }}
and in the script computed I put ...mapState('language', ['textProp'])
which the language is a VUEX module:
export default {
namespaced,
state() {
return {
textProp: Vue.prototype.$vuetify.t('$vuetify.textProp')
}
}
}
Now lets come to my issue:
I need to loop through a list of items, each item contain a dynamic text which it change according to the selected language, so this is the HTML template:
<v-list>
<v-list-tile
v-for="item in items"
:key="item.title"
:to="item.to"
router>
<v-list-tile-action>
<v-icon>{{ item.icon }}</v-icon>
</v-list-tile-action>
<v-list-tile-content>
<v-list-tile-title>
{{ item.title }}
</v-list-tile-title>
</v-list-tile-content>
</v-list-tile>
</v-list>
and the script is:
export default {
data() {
return {
items: [
{ title: this.home, to: '/', icon: 'home' },
{ title: this.orgsTxt, to: '/orgs', icon: 'business' },
{ title: this.peopleTxt, to: '/people', icon: 'people' },
{ title: this.servicesTxt, to: '/services', icon: 'store' }
],
}
},
computed: {
...mapState('language', [
'home',
'orgsTxt',
'peopleTxt',
'servicesTxt',
]),
},
}
my problem is with the referencing the text in title, and I can't put it created()
because the text will not change when the user change the language, and I don't wont to hard code each list item.
sorry for explaining too much and thanks in advance.