js/ts文件中,导入i18n报错:Must be called at the top of a `setup` function

import { useI18n } from 'vue-i18n';
const { t } = useI18n();
 
会在非组件情况下报错:

 

此时我们需要将上述导入方式改为:

import i18n from '@/lang/i18n';//@/lang/i18n为语言包位置
const { t } = i18n.global;
posted @ 2023-07-10 11:50  大萨特  阅读(2482)  评论(0)    收藏  举报