vue.js - VueJS slots with v-for loop do not display proper elements -
i'm trying create component displays subset of items passed it.
so far have 'sublist' component named slots follows:
... data: () => ({ startitem : 0 }) ... <template> <div> <slot v-for="ctr in maxitems" :name="'s-' + (ctr + startitem - 1)"></slot> </div> </template>
in parent following:
<sublist :max-items="5"> <div v-for="(i,index) in items" :slot="'s-'+index"> {{index}} </div> </sublist>
when loads, renders fine:
0 1 2 3 4
however when increment startitem
in sublist
component, output becomes:
5 1 2 3 4
so removes 0th slot , stuffs slot 5 in place. proper way replace slots or make them "dynamic"? i'm using vuejs 2.4.2
thanks @steveholgado found answer: had add :key
attribute in parent v-for
, wrap each slot
in child in own div:
<template> <div> <div v-for="ctr in maxitems"> <slot :name="'s-' + (ctr + startitem - 1)"></slot> </div> </div> </template>
Comments
Post a Comment