我在下面的i18n文件中定义了要使用的本地化文件,这些文件存储在src->语言环境中
return None
虽然我将其导入main.ts文件中并在Vue构造函数中使用它会引发错误,提示它与Component构造函数不匹配:
import Vue from 'vue';
import VueI18n from 'vue-i18n';
Vue.use(VueI18n);
const loadLocaleMessages = function () {
const locales = require.context('./locales', true, /[A-Za-z0-9-_,\s]+\.json$/i);
const messages = {};
locales.keys().forEach(key => {
const matched = key.match(/([A-Za-z0-9-_]+)\./i);
if (matched && matched.length > 1) {
const locale = matched[1];
messages[locale] = locales(key);
}
});
return messages;
};
export default new VueI18n({
locale: process.env.VUE_APP_I18N_LOCALE || 'en',
fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'en',
messages: loadLocaleMessages()
});
如果我没有在上面的代码中通过i18n,它可以很好地编译,但是在此更改后出现以下错误。
import i18n from './i18n';
new Vue({
i18n,
router,
store,
render: (h: any) => h(App),
}).$mount('#app');
在TypeScript项目中导入和使用此库的正确方法是什么。