Skip to content
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

<template> tag with v-for render undefined #4564

Closed
shjyh opened this issue Dec 26, 2016 · 13 comments · Fixed by #4572
Closed

<template> tag with v-for render undefined #4564

shjyh opened this issue Dec 26, 2016 · 13 comments · Fixed by #4572
Assignees

Comments

@shjyh
Copy link

shjyh commented Dec 26, 2016

if i use a Array as a prop of custom component,
the template element with v-for directive just render undefined

<component :list="list"></component>
<template v-for="item of list">{{item.name}}</template> <!-- output undefined -->

it's strange.
only template element tag has this problem.

Vue.js version

2.1.7

Reproduction Link

simple demo here
https://github.com/shjyh/vue_error_demo/tree/master/2016-12-26

@posva
Copy link
Member

posva commented Dec 26, 2016

The template tag is meant to wrap multiple elements like:

<template v-for="item in list">
   <span>{{ item.key }}</span>
  <span> {{ item.name }}</span>
</template>

In your case you should simply use <span v-for="item in list"></span> to wrap the text nodes

@posva posva closed this as completed Dec 26, 2016
@shjyh
Copy link
Author

shjyh commented Dec 26, 2016

I know.
but the real scene in my code is more complex than this demo. I need to wrap multiple elements in a template tag, but the output is undefined.
and it works all right in v2.1.6.
it seems all v-for directive inside a template tag output undefined if there's child component with props bind before the tag.
like this:

<component :list="list"></component>
<template v-if="ready">
        <div v-for="item of items">{{item.name}}</div> <!--here undefined-->
        <!-- ...other -->
</template>

and is this the expected behavior?

@posva
Copy link
Member

posva commented Dec 26, 2016 via email

@posva posva reopened this Dec 26, 2016
@shjyh
Copy link
Author

shjyh commented Dec 26, 2016

at least the template like:

<component :list="list"></component>
<template v-for="(item,index) of list2">
    <div>{{index}}</div>
    <div>{{item.name}}</div>
</template>

works wrong.

and sometimes the v-for directive inside a template tag also output undefined, and works ok if I modified some code. I really don't know how it happen;

@simplesmiler
Copy link
Member

Does happen in 2.1.7: https://jsfiddle.net/14dtfh51/8/
Does not happen in 2.1.6: https://jsfiddle.net/14dtfh51/9/

@defcc
Copy link
Member

defcc commented Dec 26, 2016

Seems an issue with normalize children. I'll try to make a patch.

@dankuck
Copy link

dankuck commented Jan 6, 2017

I'm still seeing a similar problem when running against the latest code.

Example: https://dankuck.github.io/TiltMaker/buggy.html

References: https://cdn.rawgit.com/vuejs/vue/dev/dist/vue.js

Github: https://github.com/dankuck/TiltMaker

@buzdyk
Copy link

buzdyk commented Feb 23, 2017

So, what's going on here.. Any updates?

@posva
Copy link
Member

posva commented Feb 23, 2017

if there's a bug, please, open a new issue with the corresponding repro

@doydoydoy
Copy link

Any updates regarding this? I am getting the same error. My code is very similar to the first post.

@nirazul
Copy link

nirazul commented Oct 17, 2017

As many will stumble upon this issue:

The error introduced in vue@2.5.0 is similar to the one reported in this issue, but in fact it is a regression that has already been fixed in vue@2.5.1. Just update to the latest patch release, which is vue@2.5.2 at the moment.

Issue: #6790

Commit: 1f84dd1

Release: https://github.com/vuejs/vue/releases/tag/v2.5.2

@dankuck
Copy link

dankuck commented Oct 17, 2017

I finally solved my problem when I realized that I was loading a separate version of Vue on the page. Only the one webpacked into my distribution files was necessary.

@zikyfranky
Copy link

zikyfranky commented Oct 10, 2022

I was facing the same issue, and nothing on here solved it for me (using Vue3)

After lot of frustration, I discovered I caused the issue, as I was binding v-for, check your code, it should be v-for="" and not :v-for=""

I only had to remove the colon : and it works now.

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

Successfully merging a pull request may close this issue.

9 participants