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

Add warning for ambiguous usage of slot-scope and v-for on the same element #6817

Closed
hit12369 opened this issue Oct 14, 2017 · 3 comments
Closed

Comments

@hit12369
Copy link

Version

2.5.2

Reproduction link

https://jsfiddle.net/xrecft4f/

Steps to reproduce

parent1 is not rendering anything, while parent2 is rendering correctly.

What is expected?

v-for should work if the slot-scope is given on the element.

What is actually happening?

As visible in the fiddle, parent1 is not rendering anything. Right now it only works if it's wrapped inside a template tag.

@HerringtonDarkholme
Copy link
Member

HerringtonDarkholme commented Oct 16, 2017

I don't know if this should be fixed. I would suggest users to explicitly use template.
Compiler will have a hard time to infer which directive should be first expand.

Consider this example:

<child>
    <div slot-scope="props" v-for="i in props.items"/>
</child>

We should first expand it to <template slot-scope="props"> ... </template>, right?

But if we add an :slot option, it doesn't seem right.

<child>
    <div slot-scope="props" v-for="i in parentItems" :slot="props[i]"/>
</child>

For this template, it should be compiled to

<template v-for="i in parentItems">
  <template slot-scope="props" :slot="props[i]">
   <div></div>
  </template>
</template>

Update:

maybe we can use a simpler strategy:
always prefer expanding slot-scope over v-for unless there is a :slot binding.

@yyx990803
Copy link
Member

The usage here is indeed ambiguous, I also suggest using an explicit <template> wrapper if you need v-for. We should add a warning for this case.

@yyx990803 yyx990803 changed the title v-for does not work with slot-scope on non template element Add warning for ambiguous usage of slot-scope and v-for on the same element Oct 19, 2017
lovelope pushed a commit to lovelope/vue that referenced this issue Feb 1, 2018
@razbakov
Copy link

It looks like warning is not possible to solve in some cases, see #7722

f2009 pushed a commit to f2009/vue that referenced this issue Jan 25, 2019
aJean pushed a commit to aJean/vue that referenced this issue Aug 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants