首页 > 解决方案 > 使用 quasar 框架在 vuex 模块中导入 vue-i18n

问题描述

我的 i18n 启动文件

import { boot } from 'quasar/wrappers';
import { LocalStorage } from 'quasar';
import messages from 'src/i18n';
import { createI18n } from 'vue-i18n';
    
const storedLang = LocalStorage.getItem('anty-locale');
    
const i18n = createI18n({
  locale: storedLang && storedLang === 'en' ? 'en-US' : 'ru-RU',
  messages,
});
    
export default boot(({ app }) => {
  app.use(i18n);
});
    
export { i18n };

当我尝试像这样导入 vuex js 文件时

import { useI18n } from 'vue-i18n';

const { t } = useI18n({ useScope: 'global' });

我发生错误 SyntaxError: Must be called at the top of a setupfunction

import i18n from 'boot/i18n';
i18n.t('common.user') //also doesn't work

有什么正确的方法可以在 .js/.ts 文件中导入 i18n 吗?

标签: vuejs3quasar-framework

解决方案


推荐阅读