vue 实现v-for循环回来的数据动态绑定id
时间:2021-05-11 08:52:39|栏目:vue|点击: 次
如下所示:

代码效果图!!!!!
<ul>
<li v-for="(site,index) in sites" :key="index" :id="forId(index)">
<span class="channel-li-li-border">
<span class="firstLevel">{{site.name}}</span>
</span>
</li>
</ul>
<script>
new Vue({
el: '#cat2s',
data: function(){
return {
brandList: [],
sites: [
{ name: '품질검수 서비스' },
{ name: '배송물류 서비스' },
{ name: '브랜드사 리스트'}
]
}
},
methods: {
forId:function(index){
return "forid_" +index
},
}
})
</script>






