[Vuejs]-Vue router incrementing my route params id by plus one

0๐Ÿ‘

I had the same issue. Turns out Vuex automatically parses this.$route.params.id as string instead of Number. I solved it by using javaScript Number() method. In your case this would be:

nextQuestion() {
   return (Number(this.$route.params.id++));
}

or alternatively say your route view is post/question/1, you can add a handler to your button like so: @click="$router.push(nextQuestion)"then in your computed lifecycle hook, do this:

nextQuestion() {
    return "post/question/"  + (Number(this.$route.params.id) + 1)
}

Leave a comment