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
support the use of slot in layout files #190
Comments
|
Can you provide an example of what you are trying to do @dohomi ? |
|
Hello @Atinux here a simple example to get content into the toolbar and content section of an app index.vue default_layout.vue Currently I do this through a custom component and leave the |
|
Hi @dohomi It's not possible with But nothing is impossible with vue.js 😄 You can create a
<template>
<div>
<header>
<slot name="toolbar"></slot>
</header>
<content>
<slot name="content"></slot>
</content>
</div>
</template>And then, in your pages, you can can import the layout (we use it as <template>
<page>
<div slot="toolbar">
<h2 class="md-title">Welcome to index</h2>
</div>
<div slot="content">
<p>her comes the content...</p>
</div>
</page>
</template>
<script>
import page from '~/layout/default'
export default {
components: { page }
}
</script> |
|
Hi @Atinux thats how I am doing it right now. Thanks for the example and good to know that I did it in the right way. |
|
Hi @Atinux @alexchopin is it somehow possible to use |
|
never mind... I got it working with tweaking the css and now the structure respects. Still there might be some workflows where |
|
<router-view class="view one"></router-view>
<router-view class="view two" name="a"></router-view>
<router-view class="view three" name="b"></router-view>const router = new VueRouter({
routes: [
{
path: '/',
components: {
default: Foo,
a: Bar,
b: Baz
}
}
]
}) |
|
Any updates on this with current/forthcoming versions? |
|
We will work on it, after long thoughts I don’t think layouts was a great idea but instead rely on a App.vue |
|
Any update on this? I've found the lack of slots really hard to work around. I often need to change the contents of a default toolbar in the layout depending on certain pages' actions needs. I've been bending over backwards to try to handle this. Vue slots were so easy to use and would be great to have again. |
|
I need this one too. Aside from what @Atinux suggested, is it possible to programatically or suggested to programatically inject a component to layout's component? Same use case as the others which is modifying a toolbar's contents. |
|
I'm not sure if this is possible, but what if nuxt kind of do something like this behind the scene? so that the slots in the layout is accessible within page components? |
|
To complete the trifecta of cartoon network avatars +1 for layout slots! |
|
I hope this issue could be reopened |
|
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
|
Very sad that this is not supported. |
|
Hi guys ! Any update about this ? Graphically it would be seen as: FIXED (app) Toolbar having common links to all pages both "app", I mean, no-scrollable, fixed on top Any other way to implement that ? I'm trying to get off that idea but seems not to be easy Thanks ! |
|
Would love to see this! |
|
Any update on this? Would love to see it implemented! |
|
+1 can we get this feature, please? +1 for layout slots. I hope someone is reading this, otherwise I'll open a new ticket and reference this. PS. Not sure if Nuxt has changed significantly from 2017 when this comment was made: |
|
Portal-vue helps me. layouts/default.vue <template>
<div>
My header
<PortalTarget name="under-header" />
<nuxt />
</div>
</template>pages/index.vue <template>
<div>
<Portal to="under-header">
My under header
</Portal>
My body
</div>
</template>It works for me. |
|
That seems like a possibility but not a very nice one structurally... But for small changes, it's just fine. You might not want to use too many of those portals though, it might get confusing otherwise. |
|
portal-vue looks promising, but the lack of SSR support is a non-starter for me. FWIW, it appears that Vue.js v3 will have portals as a first-class feature: https://github.com/vuejs/vue-next/blob/62a1bcbab0ebea513bb417d9f1485e64b36a6f5a/README.md |
|
+1 for slots in layout files so we can get SSR support |
|
@ the stale bot, this is a feature request so there isn't much to say about that. |
|
Thanks for your contribution to Nuxt.js!
Issues that are labeled as |
|
@ stale bot: please keep this open...pretty please? |
|
Would love to have this feature and have layouts in SSR directly supported. |
|
How can i achieve this ? |
|
+1 |
|
+100! |
|
Would be really helpful. |
|
Portal-vue worked for me to inject nav drawer content per page, though I don't need SSR for this content. Would be nice to have support for slots in layouts without this hack... +1 |
|
+1 |
|
Like I said, the actual layouts cannot support easily since we directly use We plan to support this with Nuxt 3 with the |
|
Thanks, but in my case I have preferred to not use an additional package. components/grid/default.vue <template>
<nav>
<slot name="nav"/>
</nav>
<main>
<slot/> //default slot
</main>
<footer>
<slot name="footer"/>
</footer>
</template>pages/index.vue <template>
<GridDefault> // component
<div slot="nav">...</div>
<h1>Some page</h1>
<p>Some paragraph</p>
<div slot="footer">...</div>
</GridDefault>
</template> |
|
Yeah using a component as a root element doesn't behave as expected. I've tried this as in the first example from way back, creating a The wrapping root component doesn't get access to root instance data props, or even vuex states. I have a I also have this same data stored in vuex state, but when attempting to access it I get null. import { mapGetters } from 'vuex'
export default {
mounted() {
console.log(this.pageProps) /// logs out null
},
computed: {
...mapGetters({
pageProps: 'base/page'
}),
}
} I suppose it might suffice if you only want to put slots in it, but it won't render any data. Layouts need to render slots, just like Vue does. |
|
This is now possible in Nuxt 3, this can probably be closed. I have to add a back button in my app-header which is in a layout. |
|
@mrleblanc101 how is this possible in Nuxt 3 ? |
Hello,
it would be nice if
slotareas would assignable in layout files. Often parts of the pages need to be rendered inside of the top toolbar. ThanksThe text was updated successfully, but these errors were encountered: