我有一个可以在组件中访问的vuex存储,但我正试图在Quasar框架中的Vue应用程序中访问该存储,因此无法访问该存储。
我不确定我是否没有正确导入商店。这是我能找到的最后一个问题,但没有完全回答:从路由器调用Vuex存储模块时返回null
路由器/index.js
import { route } from "quasar/wrappers";
import {
createRouter,
createMemoryHistory,
createWebHistory,
createWebHashHistory,
} from "vue-router";
import routes from "./routes";
import { useStore } from "vuex";
import { computed, ref } from "vue";
const store = useStore();
export default route(function (/* { store, ssrContext } */)
{
const store = useStore();
console.log(store); <--RETURNS UNDEFINED-------
const createHistory = omitted
const Router = createRouter({
omitted
});
<--THIS IS WHAT I'M TRYING TO IMPLEMENT, BUT CAN'T
ACCESS (BUT NOTE THAT I CAN'T EVEN ACCESS THE STORE ABOVE)
Router.beforeEach(function (to, _, next) {
if (to.meta.requiresAuth &&
!store.state.auth.isAuthenticated) {
next("/auth");
} else if (to.meta.requiresUnauth &&
store.state.auth.isAuthenticated) {
next("/coaches");
} else {
next();
}
});
return Router;
});
我需要更改这一行:
export default route(function ({ store, ssrContext } */) {
到此:
export default route(function ({ store} ) {
我不知道为什么我不能用其他方式导入商店,但胜利就是胜利!