Vuejs + Laravel 路由器重定向问题
Vuejs + Laravel router redirection issue
登录后,页面应在仪表板组件上重定向,它会重定向,但随后会再次重定向到 laravel 应用 url
路由:我用过Vue Router
const routes = [{
path: '/dashboard',
name: 'uDashboard',
component: uDashboard
}];
正在提交表单
methods: {
submit: function() {
axios.post('api/login', this.form).then(response => {
if (response.status == 201) {
this.$router.push({name: 'uDashboard'});
}
})
}
}
使您的代码阻止表单提交的默认操作,如下所示:
methods: {
submit: function(e) {
e.preventDefault(); // <-- added this
axios.post('api/login', this.form).then(response => {
if (response.status == 201) {
this.$router.push({name: 'uDashboard'});
}
})
}
}
登录后,页面应在仪表板组件上重定向,它会重定向,但随后会再次重定向到 laravel 应用 url
路由:我用过Vue Router
const routes = [{
path: '/dashboard',
name: 'uDashboard',
component: uDashboard
}];
正在提交表单
methods: {
submit: function() {
axios.post('api/login', this.form).then(response => {
if (response.status == 201) {
this.$router.push({name: 'uDashboard'});
}
})
}
}
使您的代码阻止表单提交的默认操作,如下所示:
methods: {
submit: function(e) {
e.preventDefault(); // <-- added this
axios.post('api/login', this.form).then(response => {
if (response.status == 201) {
this.$router.push({name: 'uDashboard'});
}
})
}
}