我正在使用vue-i18n
我的翻译,效果很好!但是当我在单个文件组件的函数中使用该this.$t()
函数时data
,翻译不起作用。
<template>
<VFooter
app
height="auto"
color="secondary">
<VLayout
justify-center
row
wrap>
<VBtn
v-for="link in links"
:key="link.name"
:to="{ name: link.name }"
flat
round
active-class>
{{ link.label }}
</VBtn>
<VFlex
py-3
text-xs-center
xs12>
©{{ currentYear }} — <strong>{{ $t('site_name') }}</strong>
</VFlex>
</VLayout>
</VFooter>
</template>
<script>
export default {
name: 'TheSiteFooter',
data() {
return {
links: [
{ name: 'what-is-pinshop', label: this.$t('footer.what_is_pinshop') },
{ name: 'contact-us', label: this.$t('footer.contact_us') },
{ name: 'cookie-policy', label: this.$t('footer.cookie_policy') },
{ name: 'privacy-policy', label: this.$t('footer.privacy_policy') },
{ name: 'terms-and-conditions', label: this.$t('footer.terms_and_conditions') },
],
};
},
computed: {
currentYear() {
return new Date().getFullYear();
},
},
};
</script>
但是,如果我data
只使用翻译键进行更改,然后在我的模板中使用例如{{ $t('footer.what_is_pinshop') }}
加载的翻译是正确的。为什么会这样?我正在使用beforeEnter
路由器保护来更改翻译。我遵循了这个例子。
更新
如果我将links
其作为计算属性,则翻译有效。那么为什么它不仅仅发生在data
财产中呢?我也试过了this.$i18n.t()
,但没有