猿问

Laravel CRUD Axios Vue

我在 Vue/Laravel 中创建我的第一个 CRUD,现在我尝试将创建发送到我的后端应用程序,这是我的代码:


前端:


async addDespesa() {

  let uri = "api/despesas/create";

  const response = await axios.get(uri, this.despesa).then((response) => {

    this.$router.push({ name: "despesas" });

  });

},

后端:


public function create()

{

    //

}

在浏览器上检查时出错:


>[vue-router] Route with name 'despesas' does not exist 


>Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/".

    at createRouterError 

at createNavigationDuplicatedError

at HashHistory.confirmTransition

at HashHistory.transitionTo

at eval

at HashHistory.push

at new Promise

 at VueRouter.push

at eval


慕容3067478
浏览 82回答 1
1回答

慕田峪7331174

您的后端看起来不错,问题出在.then您的 Axios 调用部分:this.$router.push({ name: "despesas" });您应该检查您的前端路由(可能在名为 的文件中routes.js)并确保您有一个名为 的路由despesas。所以像这样:let routes = [    {        'path': '/path/to/despesas',        'name': 'despesas',        component: require('./path/to/despesas-component').default    },        ...    other routes];
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答