我想在getter中使用i18n $t作为静态标签。我该怎么做呢?
我试过这样导入:
import { i18n } from '../../locales/i18n.js';
const getters = {
guaranteePolicies: state => {
let guaranteesState = state.rangeUpdateData.guarantees;
let guarantees = [{
value : "",
label : i18n.t("chooseGuarantee"),
disabled : true
}];
for (let index in guaranteesState) {
guarantees.push({
value : guaranteesState[index].ID,
label : guaranteesState[index].Name
});
}
return guarantees;
}
}
但是它给我的错误是Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 't')
Thanks in advance:)
想想怎么用!
我不是用大括号导入i18n,而是像这样导入:
import i18n from '../../locales/i18n.js'
和访问$t函数,我使用
label : i18n.global.t("chooseGuarantee")
它工作得很好!希望对大家有所帮助:)