LinusBorg / portal-vue

A feature-rich Portal Plugin for Vue 3, for rendering DOM outside of a component, anywhere in your app or the entire document. (Vue 2 version: v2.portal-vue.linusb.org)
http://portal-vue.linusb.org
MIT License
3.9k stars 187 forks source link

Pass data from portal-target parent to portal content #360

Closed lgarczyn closed 2 years ago

lgarczyn commented 2 years ago

Hi, and thanks for your work.

My use case is pretty simple, I have a sidebar on every page, that is naturally outside of the router view.

I want this sidebar to be partially populated by the page. The simplest way to do that is for the sidebar to define a <portal-target name="sidebar"> and every page to define a <portal to="sidebar">

However, I want to pass the current state of the sidebar (minified or not) to whatever is currently populating the sidebar.

This could be done pretty easily, like this

sidebar.vue

<portal-target name="sidebar" :is-minified="isMinified" />

page.vue

<portal>
  <template #default="{isMinified}">
     ...
  </template>
</portal>

This would simply require to deconstruct the $props object received by <portal-target>, and to pass it to <portal> as scoped slot parameters.

LinusBorg commented 2 years ago

https://portal-vue.linusb.org/api/portal-target.html#slotprops

lgarczyn commented 2 years ago

Sorry for that, don't know how I missed it