Skip to content

Could you please support using symbol value for ":key" field(when using v-for doing list rendering)? #7936

@gitby15

Description

@gitby15

What problem does this feature solve?

When I using "v-for" to render an list, every "instance" in the list has an "id",
I would like to use a symbol type to express my "id" , and fill my "id" into ":key".
Every thing is OK until my "id" has duplicate(Example: push same "instance" into list twice by mistake)

In function "checkDuplicateKeys", when Vue detected duplicate key, it will log a warning, the warnning code is :

"warn(
            ("Duplicate keys detected: '"   key   "'. This may cause an update error."),
            vnode.context
          );"

When the file "key" is symbol type, the browser will throw an error because jointing a symbol value with string, and then byebye my application.

I check the document, It didn't tell us that we can use an symbol into key, so I think it is not a bug.
So, could you please support symbol type in list rendering?

What does the proposed API look like?

  • {{item.content}}
<script> import ... export default Vue.extend({ data(){ return { list:[{id:Symbol('id), content:'a'},{id:Symbol('id), content:'b'},{id:Symbol('id), content:'c'},{id:Symbol('id), content:'d'}] } } }) </script>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions