我想在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')
(预先谢谢:)
发布于 2022-07-12 13:18:52
想办法如何使用它!
我不是用花括号导入i18n,而是像这样导入:
import i18n from '../../locales/i18n.js'
对于访问$t函数,我使用
label : i18n.global.t("chooseGuarantee")
而且它运行得很完美!希望这对某人有帮助:)
https://stackoverflow.com/questions/72950249
复制相似问题