简体   繁体   中英

Laravel CRUD Axios Vue

Im creating my first CRUD in Vue/Laravel and now I'm trying to send a create to my backend application, this is my code:

Frontend:

async addDespesa() {
  let uri = "api/despesas/create";
  const response = await axios.get(uri, this.despesa).then((response) => {
    this.$router.push({ name: "despesas" });
  });
},

Backend:

public function create()
{
    //
}

Errors in inspect on Browser:

>[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

Your backend seems fine, the problem is in the .then part of your Axios call:

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

You should check your frontend routes (probably in a file called routes.js ) and make sure you have a route named despesas . So something like this:

let routes = [
    {
        'path': '/path/to/despesas',
        'name': 'despesas',
        component: require('./path/to/despesas-component').default
    },
    
    ...

    other routes
];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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