【问题标题】:Vue Router Warning and Router.push is not FunctioningVue 路由器警告和 Router.push 不起作用
【发布时间】:2021-12-06 23:48:22
【问题描述】:

在得到 adonis 项目的响应后,我正在尝试路由到另一个页面。调用 post 方法正在工作。但是router.push('/') 无法正常工作。每次提交b-from时只重新加载登录页面。

     async login({ commit, state }) {
         console.log("Login")
       try {
         const response = await HTTP()
           .post('/admin/login', {
             email: state.loginEmail,
             password: state.loginPassword
           })
           .then(response => {
             console.log("Ok")
             console.log(response.data)
             if (response.data == 'UserNotFoundException') {
               alert('User not found')
               router.push('/')
             }
             if (response.data == 'PasswordMisMatchException') {
               alert('password not ms')
               router.push('/')
             }
             if (response.data.token) {
               console.log(response)
               //commit('setToken', response.data.token)
               router.push('/')
             } else {
               router.push('/')
             }
           })
           console.log(response)
           //return router.push('/')
       } catch (error) {
         console.log(error)
       }
     },

路线:

routes: [
    {
      name: "FullLogin",
      path: "/login",
      component: () => import("@/views/authentication/FullLogin"),
    },
    {
      
      path: "/",
      redirect: "/dashboard/docs-dashboard",
      component: () => import("@/layouts/full-layout/FullLayout"),
      children: [
        {
          name: "Dashboard",
          path: "/dashboard/docs-dashboard",
          component: () => import("@/views/dashboards/docsDashboard"),
        },
       ]
    }
]
router.beforeEach((to, from, next) => {
    next() 
})

我不明白为什么router.push('/') 没有路由。

【问题讨论】:

    标签: vue.js vue-router


    【解决方案1】:

    根据docs

    注意:在 Vue 实例内部,您可以通过 $router 访问路由器实例。因此,您可以调用 this.$router.push。

    【讨论】:

    • 登录是vuex store中的一个动作,
    • 问题是每次,我提交b-form,它只会重新加载登录页面。你明白了吗?
    • @azam,您最好使用名称进行路由。试试router.push({ name: 'Dashboard' })
    • 它是b-form,@submit.prevent="action" 解决了问题,好的
    猜你喜欢
    • 2018-08-15
    • 2021-07-18
    • 2018-03-31
    • 2021-06-27
    • 1970-01-01
    • 2018-12-15
    • 2021-10-04
    • 2020-02-19
    • 2017-09-22
    相关资源
    最近更新 更多