0

Strange issue, I am trying to create a pagination system and I am trying to increase the next page value by 1. However as you can see the value is appended instead of increasing the value.

this.page = 1

<a v-if="this.total_pages > this.page" class="link" :href="'/cryptocurrency/market-cap?p='+(this.page + 1)">></a>

The above returns p=11 vue seems to append the 1 to the original page value of 1 instead of increasing the page value to 2.

If however I do the following it seems to work and decreases the p value by 1.

<a v-if="this.total_pages > 1 & this.page > 1" class="link" :href="'/cryptocurrency/market-cap?p='+(this.page - 1)" ><</a>
2
  • 1
    Is this.page a string or a number? If it is a string, you will need to convert it to a number first, i.e. (+this.page + 1) Commented Aug 3, 2021 at 12:48
  • 1
    And it should be &&, not & Commented Aug 3, 2021 at 12:59

1 Answer 1

2

That's not a Vue issue. It's more likely you're running into JS' loose type casting. I assume this.page is not a number but a string value. Therefore you're adding '1' + 1 in the first example which leads to 11 (since JS treats both as string and concatenates them).

However, if you're trying tu do something like '1' - 1 JS casts the initial 1 as a number instead and resolve the calculation properly.

So to solve your problem you just have to use a proper type for this.page or cast it to a number on execution, like this:

<a :href="'/cryptocurrency/market-cap?p='+(parseInt(this.page)+ 1)">></a>

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks yes this was the problem, I ended up adding the following and it has done the trick this.page = parseInt(urlParams.get('p'));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.