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

Slot property of data object doesn't work in a render function's createElement() #11519

Closed
avxkim opened this issue Jul 15, 2020 · 3 comments
Closed

Comments

@avxkim
Copy link

avxkim commented Jul 15, 2020

Version

2.6.11

Reproduction link

https://codesandbox.io/s/vigilant-diffie-shhg8?file=/src/components/Wrapper.js

Steps to reproduce

  1. Create 2 functional components without templates, use render functions.
  2. In a Button.js create a component with slot named "icon"
  3. In a Wrapper.js create a component with the Button component we created earlier, and use slot property in order to place contents of wrapper inside an "icon" slot of the button component.

What is expected?

Contents must be rendered inside a named slot

What is actually happening?

Contents not being displayed in a named slot

@posva
Copy link
Member

posva commented Jul 15, 2020

Hi, thanks for your interest but Github issues are for bug reports and feature requests only. You can ask questions on the forum, the Discord server or StackOverflow.


slot is for the parent: https://vuejs.org/v2/guide/render-function.html#The-Data-Object-In-Depth

You need to do something like

export default {
  name: "Wrapper",
  functional: true,
  render(h) {
    return h(Button, { scopedSlots: {
      icon: () => h('span', {}, 'its from wrapper')
    } });
  }
};
export default {
  name: "Button",
  functional: true,
  render(createElement, { scopedSlots }) {
    return createElement("button", {}, scopedSlots.icon());
  }
};

@posva posva closed this as completed Jul 15, 2020
@avxkim
Copy link
Author

avxkim commented Jul 15, 2020

Thanks, for the quick reply, but i still don't understand the purpose of slot, could you throw an example with it? Why scopedSlots in my case would do a job? Isn't they are used when you pass some data?

@SamirGuo
Copy link

SamirGuo commented Aug 30, 2020

There is a problem with this solution. Because scopedSlots will always call the render function to generate a new vnode every time when you getting vnode. So no matter when you get the vnode, the vnode.elm is undefined

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

3 participants