router.push()不会在VUE中重新加载路由器视图

问题描述 投票:0回答:1

我为我的自托管应用提供了简单的身份验证系统。通过有效的用户名和密码后,我需要重定向路由器视图。

[不幸的是,当我打电话给router.push("/")时,什么都没有发生。然后,我必须再次单击“登录”或手动重新加载页面或使用router.go()

登录后我无法重新加载所有页面,我只需要更新router-view

我搜索了很多问题,但没有答案。

export const authentication = {
 namespaced: true,
 state: initialState,
 actions: {
 login({
   dispatch,
   commit
 }, {
   username,
   password
 }) {
   commit("loginRequest", {
     username
   });

   userService.login(username, password).then(
     user => {
       commit("loginSuccess", user);
       // FIXME
       // when it is called it always generate error `undefinded`...
       router.push({
         url: "/"
       }).catch(err => {
         console.log(err);
       });
       // router.go(); // I can not do this!
     },
     error => {
       commit("loginFailure", error);
       dispatch("alert/error", error, {
         root: true
       });
     }
   );
 },
 logout({
  commit
 }) {
   userService.logout();
   commit("logout");
 }
};

你有什么想法,怎么了?

vue.js push vue-router reload
1个回答
0
投票

您是否尝试过这个:this.$router.push({ path: '/' });

© www.soinside.com 2019 - 2024. All rights reserved.