这应该相当简单,但我无法弄清楚。我想从 vue 路由器的导航守卫中设置一个值。我什至不再关心这个值的去向,只是某处。可能在 App 根目录上,也可能在组件上。随处。
到目前为止,我已经尝试过:
router.beforeResolve((to, from, next) => {
// this throws Warning "Method "setValue" has type "boolean" in the component definition. Did you reference the function correctly?"
MyComponent.methods.setValue(true);
// this works, but only here
next(vm=>{ vm.value=true });
});
router.afterEach((to, from) => {
// no vm. Same error on component method.
});
我真的很想避免使用 Vuex,因为(到目前为止)它只是我想传递的一个微弱的值。有什么想法吗?