Skip to content

v-else and v-once on custom component inside v-for #4182

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
fmairesse opened this issue Nov 12, 2016 · 4 comments · Fixed by #4200
Closed

v-else and v-once on custom component inside v-for #4182

fmairesse opened this issue Nov 12, 2016 · 4 comments · Fixed by #4200

Comments

@fmairesse
Copy link

Here is a list rendering using a custom component and the v-once directive:

<li v-for="item of items" :key="item.model.id">
    <item :model="item.model" v-once></item>
</li>

JsFiddle using [email protected]
Note that this does not work using [email protected], unless we remove the v-once directive.

Now let's add a conditional rendering:

  <li v-for="item of items" :key="item.model.id">
    <span v-if="item.model.id===1">BOB</span>
    <item :model="item.model" v-else v-once></item>
  </li>

JsFiddle using [email protected]
JsFiddle using [email protected]
This fails using [email protected] with the error:

Property or method "item" is not defined on the instance but referenced during render.

but works with 2.0.3 (2.0.3 failed when there was no v-else)

@posva
Copy link
Member

posva commented Nov 12, 2016

Thanks for reporting that! In the meantime, a workaround would be to move the v-once inside the component

@defcc
Copy link
Member

defcc commented Nov 13, 2016

elseBlock should be walked through too in markStaticRoots func. I'll make a PR to fix it.

@zeeshankamboh
Copy link

how to fix this problem???? any idea regarding it???

@zeeshankamboh
Copy link

actually vue is reporting a very bad error in console because of this issue. and i dont know how to tackle this problem.

@vuejs vuejs locked and limited conversation to collaborators May 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants