在Vue.JS中为div生成id

时间:2017-04-06 07:48:57

标签: html css twitter-bootstrap vue.js

考虑Bootstrap手风琴:   

  <div class="card">
    <div class="card-header" role="tab" id="headingOne">
      <div data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
       i'm not collapsed
    </div>

    <div id="collapseOne" class="collapse show" role="tabpanel" aria-labelledby="headingOne">
      <div class="card-block">
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird
        on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table,
        raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
      </div>
    </div>
  </div>

      </div>

我想用vue动态生成卡片,这样我就可以在卡片上添加这行:

  <div class="card" v-for="x in response">

它将为每个人生成一张卡片。但是,这些都是引用折叠的相同ID,因此只有其中一个打开/关闭。

要解决此问题,我尝试更改ID以更改这些行:

  <div class="card" v-for="(x,index) in response">

 <div id="{{index}}" class="collapse show" role="tabpanel" aria-labelledby="headingOne">

但这不会编译。我想不出任何其他方法。我很感激任何建议。

1 个答案:

答案 0 :(得分:5)

不要在属性中使用插值,而是使用绑定

<div class="card" v-for="(x,index) in response">
  <div :id="index" class="collapse show" role="tabpanel" aria-labelledby="headingOne"></div>
</div>