在在router中调用pinia出错,只要把
const store = useAuthStore();
const { isAuthenticated } = storeToRefs(store);
放到方法中就可以了。
router.beforeEach((to, from, next) => {
const store = useAuthStore();
const { isAuthenticated } = storeToRefs(store);
if (to.path === '/login') return next();
//获取token
if (!isAuthenticated) return next('/login')
next()
})