简体   繁体   English

Laravel Vuejs axios登录更改组件

[英]Laravel Vuejs axios login change component

I built a basic login function (backend written in laravel), I do an axios call successfully but I fail to show the home component, the url changes but the ui stays the same this.$router.push('/home'); 我建立了一个基本的登录功能(后端使用laravel编写),我成功地进行了axios调用,但是我无法显示home组件,URL更改了,但是ui保持不变this.$router.push('/home');

My Login.vue login logic: 我的Login.vue登录逻辑:

    login() {
        console.log(this.getLoginData());
        axios.post("/login", {
            email: this.email, 
            password: this.password
        })
            .then(response => {         
                console.log("success");
                this.$router.push('/home');
            })
            .catch(error => {
                console.log("error");
            })

The url changes to /home but the ui does not change. 网址更改为/ home,但ui不变。

my router: 我的路由器:

import Vue from 'vue';
import Vuex from 'vuex';
import VueRouter from 'vue-router';

import Login from '@auth/Login';
import Home from '@/js/components/Home';

Vue.use(VueRouter);
Vue.use(Vuex);

const router = new VueRouter({
    mode: 'history',
    routes: [
        {
            path: '/login',
            name: 'login',
            component: Login,
        },
        {
            path: '/',
            name: 'home',
            component: Home
        },
    ]
});

export default router;

This is my app.js 这是我的app.js

import App from '@/js/views/App';
import Auth from '@views/Auth';

Vue.use(Vuetify);
Vue.use(Vuex);

const app = new Vue({
    el: '#app',
    router: Routes,
    store: PdfStore,
    render: h => h(Auth)
});

export default app;

App.vue holds the ui which shall be used after the login proccess. App.vue保留将在登录过程之后使用的ui。 App.vue holds a <router-view></router-view> and the navigation logic in App.vue works fine updating url and changing component. App.vue拥有<router-view></router-view>并且App.vue中的导航逻辑可以很好地更新url和更改组件。

It just does not work after the login process. 它只是在登录过程后不起作用。

尝试:

this.$router.push({ name: 'home' })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM