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,在 render 函数中使用slot,如何指定多个slot呢? #4

Open
jackchoumine opened this issue Nov 2, 2020 · 1 comment

Comments

@jackchoumine
Copy link

比如 Child:

<template>
     <header>
       <slot  name="header"></slot>
      </header>
     <main>
           <slot></slot>
     </main>
     <footer>
      <slot  name="footer"></slot>
     </footer>
<template>
<script>

如何在 render 函数中渲染该组件?使用render函数定义该组件呢?

@willson-wang
Copy link
Owner

@jackchoumine

// 父组件中使用Child
render(h) {
    return h(
        Child
    )
}
// 使用render函数定义该组件
render(h) {
    return (
          h(
              'div',
              [
                    h(
                        'header',
                        [
                            this.$slots['header']
                        ]
                    ),
                    h(
                        'main',
                        [
                            this.$slots.default
                        ]
                    ),
                    h(
                        'footer',
                        [
                            this.$slots['footer']
                        ]
                    ),
              ]
          )
    )
}

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

2 participants