Home > Net >  How to add id to items when using v-for in VueJS
How to add id to items when using v-for in VueJS

Time:08-17

I have a data table and when I render those records on the website, I will add ids to the elements, each element is a different id(id="item-first"), so what to do?

 <div  v-for="(item, index) in producthots" :key="index">
          <div
            :
          >

I want when rendered, each element will have an id object

CodePudding user response:

for adding id you can bind it as like as :src and :class, it would be like this :id look at the example below:

<div :id="'CollapseState'   index" aria-expanded="false" 
></div>  

I binded the id and also for making it uniq I added index end of it so the short answer is below code:

:id="'CollapseState'   index"
  • Related