I have this v-for loop an my vue.js app:
  <div v-for="(word, index) in dictionary"> 
     // break if index > 20
     <p>{{word}}</p>
  </div>
I want to break out of the loop after rendering 20 words. How can I achieve this? I looked at the docs but did not see anything about this.
you can manipulate the array before loop start
<div v-for="(word, index) in dictionary.slice(0,20)"> 
    <p>{{word}}</p>
</div>
                        You have to create a computed value for your truncated dictionary (e.g. it is better to prepare data for rendering):
computed: {
 shortDictionary () {
   return dictionary.slice(0, 20)
 }
}
...
<div v-for="(word, index) in shortDictionary"> 
   <p>{{word}}</p>
</div>
                        For this scenario, this solution works best for me.
<div v-for="(word, index) in dictionary" v-if="index <= 20"> 
    <p>{{word}}</p>
</div>
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With