I am working with vuejs and vue-router in Rails app. I have a button which calls a nivagate
method. When user clicks on this navigate
method, it hits an API enpoint via axios
module and move to next component using this.$router.push({name: "RouteName"})
. Problem is, when user clicks multiple on this button it gives Uncaught (in promise) undefined
error in console. My guess is this error occurs because of vue-router.
My question is, how can I catch or handle this error. I am using multiple such buttons in my app so I need a generic solution.
Home.vue - component
<template>
<div>
<button
id="select_button"
@click="onSelectClick"
>
Select
</button>
</div>
</template>
<script>
export default {
onSelectClick() {
this.$`enter code here`axios.get('some-url').then(res => {
//print res on console
}).catch(err => {
// print err on console
})
this.$router.push({ name: 'route-name' }); //route-name != home
}
}
</script>
<style>
</style>
Error I get when I double(or more)-click on button
Uncaught (in promise) undefined