Vue项目中Router调用含i18n依赖的Pinia Store启动报错的问题求助
Vue项目中Router调用含i18n依赖的Pinia Store启动报错的问题求助
我现在遇到个挺头疼的问题,想请教下各位大佬。我在Vue项目的router.ts里,需要获取Pinia的storeA里的某个值,于是就在路由守卫beforeEach里调用了useStoreA()来判断状态,代码大概是这样的:
router.beforeEach((to, from, next) => { if(useStoreA().myString == "something") { next() } })
但麻烦的是,我的storeA里虽然我要用到的myString和i18n没关系,但其他状态用到了vue-i18n的翻译函数t,Store的代码是这样的:
import { useI18n } from "vue-i18n"; export const useStoreA: StoreDefinition<"storeA"> = defineStore( "storeA", () => { const t = useI18n().t; const myString = "something"; const myOtherString = t("hey"); return { myString, myOtherString } } )
结果项目启动的时候直接触发了Vue Router的警告,报错信息是:
[Vue Router warn]: Unexpected error when starting the router: SyntaxError: Must be called at the top of a...
备注:内容来源于stack exchange,提问作者Nicolas
相关产品推荐
相关产品推荐

