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

Slots with modifiers #1241

Closed
KaelWD opened this issue May 27, 2020 · 4 comments
Closed

Slots with modifiers #1241

KaelWD opened this issue May 27, 2020 · 4 comments

Comments

@KaelWD
Copy link
Contributor

KaelWD commented May 27, 2020

Version

3.0.0-beta.14

Reproduction link

https://vue-next-template-explorer.netlify.app/...

Steps to reproduce

Use v-slot with a dot in the name

What is expected?

It should be compiled to a slot 'item.name'

What is actually happening?

It's compiled to 'item', the "modifier" is ignored


vuejs/eslint-plugin-vue#1165

This works in Vue 2, it was originally slot="item.name". We use this to create slots for arbitrary properties on objects.

@yyx990803
Copy link
Member

That’s a parser level change - making it work is essentially adding a special case to the parsing rules. Ideally we should avoid that.

Is it difficult to switch to different slot names?

@KaelWD
Copy link
Contributor Author

KaelWD commented May 27, 2020

Ah I see the AST is completely different now, vue-template-compiler parses v-slot to scopedSlots instead of keeping the template element.

Is it difficult to switch to different slot names?

It's used for arbitrary property lookup on objects, so { foo: { bar: 'baz' } } can be accessed with v-slot:item.foo.bar. I suppose we could remove this ability in v3 and require users to flatten their objects first.

It looks like vue-template-compiler can do v-slot:['item.name'] but @vue/compiler-core throws Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<)

@b-strauss
Copy link

b-strauss commented May 27, 2020

Vuetify does this on their table component in combination with dynamic slot names.

https://vuetifyjs.com/en/components/data-tables/#api

var items = [
  {
    firstname: 'foo',
    lastname: 'bar',
  },
];
<v-data-table :items="items">
  <!-- this slot only applies to the firstname column. -->
  <template v-slot:item.firstname="{item}">
  </template>
</v-data-table>

The point is to differentiate the dynamic parts of the slot name from the static one.

@Justineo
Copy link
Member

Justineo commented Jun 13, 2020

IMO in Vue templates there’s a unified syntax of v-directive:arg.modifier (to learn and remember) and this change is breaking this syntax. Is there any chance we make the name part as a modifier for the v-slot directive to avoid introducing more caveats on the syntax?

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

No branches or pull requests

4 participants