首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在vue 3中的vuex getter中使用vue i18n $t?

如何在vue 3中的vuex getter中使用vue i18n $t?
EN

Stack Overflow用户
提问于 2022-07-12 09:44:44
回答 1查看 249关注 0票数 0

我想在getter中使用i18n $t作为静态标签。我怎么能这么做?

我试过这样进口:

代码语言:javascript
运行
复制
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')

(预先谢谢:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-12 13:18:52

想办法如何使用它!

我不是用花括号导入i18n,而是像这样导入:

代码语言:javascript
运行
复制
import i18n from '../../locales/i18n.js'

对于访问$t函数,我使用

代码语言:javascript
运行
复制
        label : i18n.global.t("chooseGuarantee")

而且它运行得很完美!希望这对某人有帮助:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72950249

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档