vue i18n- js文件中具有翻译变量的对象
我正在与Vue,Vue I18N和Quasar合作。
因此,我有一个JS文件,该文件包含一个带有ID和名称的对象,我在Q-SELECT选项上使用它。我希望当我更改语言时(在语言下拉下)时,几个月的标签名称也会更改。但这只有在我刷新页面时才发生。我在其他组件中使用相同的JS文件
VUE组件:
<q-select
v-model="monthValue"
:options="monthOptions()"
map-options
emit-value
option-value="id"
option-label="name"
outlined
dense
/>
import {getMonths} from "../../components/basic/Months.js";
computed: {
monthOptions() {
return getMonths;
},
montrys.js
import { i18n } from "../../boot/i18n.js";
export const getMonths = () => [
{ id: "January", name: i18n.t("MONTHS.JANUARY") },
{ id: "February", name: i18n.t("MONTHS.FEBRUARY") },
{ id: "March", name: i18n.t("MONTHS.MARCH") },
{ id: "April", name: i18n.t("MONTHS.APRIL") },
{ id: "May", name: i18n.t("MONTHS.MAY") },
{ id: "June", name: i18n.t("MONTHS.JUNE") },
{ id: "July", name: i18n.t("MONTHS.JULY") },
{ id: "August", name: i18n.t("MONTHS.AUGUST") },
{ id: "September", name: i18n.t("MONTHS.SEPTEMBER") },
{ id: "October", name: i18n.t("MONTHS.OCTOBER") },
{ id: "November", name: i18n.t("MONTHS.NOVEMBER") },
{ id: "December", name: i18n.t("MONTHS.DECEMBER") }
];
我尝试了很多事情,但是无济于事。有人有建议吗?谢谢。
i'm working with Vue, Vue i18n and Quasar.
So, i have an js file that contains an object with id and name, which i use on q-select options. I want that when i change the language (on language drop-down), the label name from months changes too. But this happens only if i refresh the page. I use the same js file in other components
Vue component:
<q-select
v-model="monthValue"
:options="monthOptions()"
map-options
emit-value
option-value="id"
option-label="name"
outlined
dense
/>
import {getMonths} from "../../components/basic/Months.js";
computed: {
monthOptions() {
return getMonths;
},
Months.js
import { i18n } from "../../boot/i18n.js";
export const getMonths = () => [
{ id: "January", name: i18n.t("MONTHS.JANUARY") },
{ id: "February", name: i18n.t("MONTHS.FEBRUARY") },
{ id: "March", name: i18n.t("MONTHS.MARCH") },
{ id: "April", name: i18n.t("MONTHS.APRIL") },
{ id: "May", name: i18n.t("MONTHS.MAY") },
{ id: "June", name: i18n.t("MONTHS.JUNE") },
{ id: "July", name: i18n.t("MONTHS.JULY") },
{ id: "August", name: i18n.t("MONTHS.AUGUST") },
{ id: "September", name: i18n.t("MONTHS.SEPTEMBER") },
{ id: "October", name: i18n.t("MONTHS.OCTOBER") },
{ id: "November", name: i18n.t("MONTHS.NOVEMBER") },
{ id: "December", name: i18n.t("MONTHS.DECEMBER") }
];
I've tried so many things, but to no avail.. Does anyone have suggestions? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该
月份
在计算属性之外定义了t
的反应性。数组需要在montroptions
中创建。如果在组件之间重复使用,则月份。js应该导出一个返回数组而不是数组的函数:That
months
is defined outside computed property disables the reactivity oft
. The array needs to be created insidemonthOptions
. If it's reused between components, Months.js should export a function that returns an array instead of an array:因此,我像Estus所说的那样尝试过,但是我不知道为什么不起作用。所以,我找到了另一种方法。
我离开了翻译发生在组件中。这样:
谢谢
!
so i tried like Estus said, but i don't know why didn't work. So, i find another way.
I left the translation happens in the component. Like this:
And
Thanks!