Twitter bootstrap 如何在vue v-for中正确使用dinamic id名称?

Twitter bootstrap 如何在vue v-for中正确使用dinamic id名称?,twitter-bootstrap,vue.js,Twitter Bootstrap,Vue.js,我试图在v-for中迭代一个div。 我正在尝试使用索引参数进行动态div id赋值,但我不知道如何正确使用它 至少我使用引导折叠将数据目标分配给渲染的div。 它不起作用 代码如下: '<div class="servizioInlista" v-for="(servizio,index) in servizi.lineaGialla.servizi">'+ '<div class="row"&g

我试图在v-for中迭代一个div。 我正在尝试使用索引参数进行动态div id赋值,但我不知道如何正确使用它

至少我使用引导折叠将数据目标分配给渲染的div。 它不起作用

代码如下:

                '<div class="servizioInlista" v-for="(servizio,index) in servizi.lineaGialla.servizi">'+
                        '<div class="row">'+
                            '<div class="col-lg-8 col-xs-8 nopadding">'+
                                '<h4 class="blu">{{servizio.nomeServizio}}</h4>'+
                            '</div>'+
                            '<div class="col-lg-4 col-xs-4>"'+
                                '<span class="pull-right nomargin"  v-on:click="mostraServiziGiallo" v-bind:class="[GiallaTutti ? \'minus\' : !GiallaTutti,\'plus\']" data-toggle="collapse" data-target="#singoloGialla.index"></span>'+                           
                            '</div>'+
                        '</div>'+
                        '<div v-bind:id="singoloGialla.index" class="row">'+
                            '<p>{{servizio.descrizione}}</p>'+
                        '</div>'+
                    '</div>'+
“”+
''+
''+
“{{servizio.nomeServizio}”+
''+

’据我所知,你想要这样的东西:

<div v-bind:id="'singoloGialla-' + index" class="row">
  <p>{{servizio.descrizione}}</p>
</div>

{{servizio.descripione}}

<。。。v-bind:data target=“”#singoloGialla-“+索引”>

所以,我们取字符串
'singoloGialla-'
,并将其和
索引
变量的动态值连接起来。当我们使用
+
操作符连接字符串和数字时,数字首先转换为字符串,然后连接到现有字符串。这不是特定于Vue的,而是正常的JavaScript行为。

在控制台中,我有以下消息:[Vue warn]:属性或方法“singoloGialla”未在实例上定义,而是在呈现过程中引用的。请确保在数据选项中声明被动数据属性。是的,我以前也尝试过,但vue发出了相同的消息。无论如何,我都在组件上使用此绑定,因此脚本的格式如下:data toggle=“collapse”data target=“\'”singoloGialla-\'+index“您是否在组件的
data
函数中定义并返回了
singoloGialla
?顺便说一句,该消息与
索引
变量无关。Vue认为
singoloGialla
是一个变量。不,singoloGialla只是一个div id名称。。。我必须将其定义为数据中的空对象吗?好的。因此,您应该确保Vue认为它是一个字符串。目前,您似乎正在对单引号进行转义,这样它就不会变成字符串。不,在这种情况下,我认为您不应该在数据中定义它。
< ... v-bind:data-target="'#singoloGialla-' + index">