A
A
Anton P.2018-07-02 08:06:29
Vue.js
Anton P., 2018-07-02 08:06:29

Is it possible to reuse slots in vue components?

There is a component responsible for the header, I pass the menu to it via <slot name="menu"></slot>.
I need this slot in two places, in the main header of the site, and in the fixed-header (it appears when the user scrolls down the site).
Vue.js throws an error during bottom manipulation, but does not crash, the site works fine!

Duplicate presence of slot "menu" found in the same render tree - this will likely cause render errors.

As far as I understand from the phrase "this will likely cause render errors", this is no longer an error, but a very important warning.
So, how important is this warning?
Is it possible to duplicate slots? Maybe it needs to be done differently? (I did not find anything about this in the documentation)
Has anyone already done this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
fl3nkey, 2018-07-02
@mrswylet

You can use render functions .

{
  components: {
    Render: {
      functional: true,
      render: (h, ctx) => ctx.props.vnode
    }
  }
}

<div class="header">
  <render :vnode="$slots.menu"></render>
</div>
<div class="fixed-header">
  <render :vnode="$slots.menu"></render>
</div>

https://en.vuejs.org/v2/guide/render-function.html...
https://en.vuejs.org/v2/guide/render-function.html...
https://en. vuejs.org/v2/api/#vm-slots

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question