Skip to content

<transition-group> children must be keyed: <div> #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
afuno opened this issue May 13, 2017 · 11 comments
Closed

<transition-group> children must be keyed: <div> #144

afuno opened this issue May 13, 2017 · 11 comments

Comments

@afuno
Copy link

afuno commented May 13, 2017

Slim:

template id='blocks-template'
	draggable v-model="blocks"
		transition-group
			div v-for="block in blocks" :key="block.id"
				| {{block.id}}

HTML:

<draggable v-model="blocks">
	<transition-group>
		<div :key="block.id" v-for="block in blocks">{{block.id}}</div>
	</transition-group>
</draggable>

Without this part of the code, everything works: <transition-group>.

Once I put the code in it, I get an error:

[Vue warn]: <transition-group> children must be keyed: <div>

I do not understand what this phrase means:

children must be keyed

What should I do with the div? I placed the div before and after thetransition-group. It did not change anything.

@David-Desmaisons
Copy link
Member

@afuno , this message is from transition-group.
I guess the problem is that block.id value should be undefined.
Could you check that?

@David-Desmaisons
Copy link
Member

@afuno , any feedback on this?

@afuno
Copy link
Author

afuno commented May 16, 2017

@David-Desmaisons yes. You helped. Thank you :)

@afuno afuno closed this as completed May 16, 2017
@rgalaxy
Copy link

rgalaxy commented Mar 13, 2018

so how you fixed it? care to share it? because i encounter same problem

@StevenVerbiest
Copy link

@rgalaxy I had the same problem and it was indeed an issue with :key being undefined.

My original code was

<div v-for="(step, index) in steps.pages" :key="step.index" v-show="index === stepIndex" v-html="step.text">
</div>

But step.index was undefined. The correct key is index

<div v-for="(step, index) in steps.pages" :key="index" v-show="index === stepIndex" v-html="step.text">
</div>

Hope this helps!

@Krassmus
Copy link

I got the same error and had all elements in v-for correctly keyed. But I forgot that I had added one <li>-element that had no key - a reload-icon in my scrollable list.

    <transition-group name="blubberthreadwidget-list" tag="ol">
            <li v-for="thread in sortedThreads"
                :key="thread.thread_id"
                :data-thread_id="thread.thread_id"
                :class="(active_thread === thread.thread_id ? 'active' : '') + (thread.unseen_comments > 0 ? ' unseen' : '')"
                :data-unseen_comments="thread.unseen_comments"
                @click.prevent="changeActiveThread">
                <a :href="link(thread.thread_id)">
                    <div class="avatar"
                         :style="{ backgroundImage: 'url(' + thread.avatar + ')' }">
                    </div>
                    <div class="info">
                        <div class="name">
                            {{ thread.name }}
                        </div>
                        <studip-date-time :timestamp="thread.timestamp" :relative="true"></studip-date-time>
                    </div>
                </a>
            </li>
            <li class="more" v-if="display_more_down">
                <studip-asset-img file="ajax-indicator-black.svg" width="20"></studip-asset-img>
            </li>
    </transition-group>

The problem was the only last <li>-element. Once I rewrote it to

<li class="more" v-if="display_more_down" key="more">

Everything worked fine.

@nanslee
Copy link

nanslee commented Feb 14, 2020

so how you fixed it? care to share it? because i encounter same problem

i encounter it, too

@tinarooot
Copy link

    <transition-group tag="div" name="slide-down" class="article-box">
        <div
                class="article-item"
                v-for="item in articleList"
                v-bind:key="item._id"
                @click="$router.push(`/article/${item.id}`)">
      </div>
    </transition-group>


[Vue warn]: <transition-group> children must be keyed: <div>

为啥?

@tinarooot
Copy link

so how you fixed it? care to share it? because i encounter same problem

i encounter it, too

怎么解决??

@trungcva10a6tn
Copy link

    <transition-group tag="div" name="slide-down" class="article-box">
        <div
                class="article-item"
                v-for="item in articleList"
                v-bind:key="item._id"
                @click="$router.push(`/article/${item.id}`)">
      </div>
    </transition-group>

[Vue warn]: <transition-group> children must be keyed: <div>

为啥?

because item._id = undefined

@liaowei960611
Copy link

The perfect solution to this problem is that the value of the set key is undefined, which is why this problem exists. The key that needs to be bound has a value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants