[Vuejs]-Vue Router beforeRouteEnter API call response not 'working'

0👍

Not sure on the logic behind it, but had to use .then() for my getVehicle response before it would work. So changed to:

getVehicle(to.params.id).then( response => {
    next( vm =>
        vm.setData(response)
    );
});

0👍

I’m not sure it will work with a function inside the beforeRouteEnter guard. Instead try call the axios get method like

let data = axios.get('/api/v1/vehicles/${to.params.id})
next(vm.setData(err, data))

This should work

👤Kwame

Leave a comment