Svelte 3 - How to loop each block X amount of times

前端 未结 2 1322
-上瘾入骨i
-上瘾入骨i 2020-12-20 14:27

I\'m hoping to find a way to iterate over an #each block a set amount of times in Svelte 3. In Vue I would do something like this:

  • 相关标签:
    2条回答
    • 2020-12-20 15:07

      An #each tag can loop anything with a length property, so:

      {#each {length: 3} as _, i}
          <li>{i + 1}</li>
      {/each}
      

      will also work, if you prefer.

      0 讨论(0)
    • 2020-12-20 15:13

      You can use {#each ...}, like:

      {#each Array(3) as _, i}
          <li>{i + 1}</li>
      {/each}
      
      0 讨论(0)
    提交回复
    热议问题