Search code examples
loopsvue.jsrangev-for

Vue v-for with variable range not working


totalLoops = 3;

Expected output: 1 2 3

Working:

<div v-for="i in 3">{{ i }}</div>

Not working:

<div v-for="i in totalLoops">{{ i }}</div>

I have searched and tried different solutions but none of them work for me. Thanks for your help.

EDIT: Sorry, bad question. This code is working properly. I found the problem was in other piece of code.


Solution

  • Don't forget to add your :key=. Anyways your code seems to be ok and it's working at my end

    <div v-for="i in 3" :key="i">{{ i }}</div>