4
<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.

How can I bind key in attributes of li's children? It only works in li itself.

1 Answer 1

4

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>

Sign up to request clarification or add additional context in comments.

1 Comment

Oh yeah, it does. Thanks. It was my HTML structure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.