简体   繁体   English

Vue.js v-for item,将属性绑定到当前索引/键

[英]Vue.js v-for item, bind attribute to current index / key

<li v-for="(value, key) in {facebook: [data], twitter: [data]}">
    <i class="icon" :class="key"></i>
    ....
</li>

Error: [Vue warn]: Trying to access non-existent property "key" while rendering. 错误: [Vue warn]: Trying to access non-existent property "key" while rendering.

How can I bind key in attributes of li 's children? 如何绑定li的孩子的属性key It only works in li itself. 它只适用于li本身。

It works as expected for me. 它对我来说是预期的。 If you inspect the items in the snippet below, you'll see the class is assigned. 如果您检查下面代码段中的项目,您会看到已分配该课程。

 new Vue({el: 'body'}); 
 <script src="//cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.min.js"></script> <li v-for="(key, value) in {facebook: ['data'], twitter: ['data']}"> <i class="icon" :class="key">{{key}}</i> </li> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM