I have two Nuxt.js layouts, default.vue and secondary.vue. There's the same footer.vue ponent that is being used in both of these layouts. I'd like to change some CSS classes inside of the footer.vue ponent based upon which layout the ponent is being used in. How Does one know what layout is being used from within a ponent nested in Nuxt.js layout?
I have two Nuxt.js layouts, default.vue and secondary.vue. There's the same footer.vue ponent that is being used in both of these layouts. I'd like to change some CSS classes inside of the footer.vue ponent based upon which layout the ponent is being used in. How Does one know what layout is being used from within a ponent nested in Nuxt.js layout?
Share Improve this question asked Jun 6, 2019 at 15:34 user782860user782860 2,7795 gold badges20 silver badges16 bronze badges 3-
You could pass down a
type
property or something depending on what ponent is using footer. So indefault.vue
when you renderfooter.vue
give it a prop type called 'default'. Same withsecondary.vue
. And then infooter.vue
check prop type and change css there. – Isaac Vidrine Commented Jun 6, 2019 at 15:37 - @IsaacVidrine I tried something like that with vuex. However, how do you create a lifestyle hook when a layout is loaded? mounted() and created() do not work in layouts. – user782860 Commented Jun 6, 2019 at 15:40
-
The lifecycle methods belong in the logic of the ponent, so of course you can't use them in the layout. That should be irrelevant though. Just pass down a property to
footer.vue
? – Isaac Vidrine Commented Jun 6, 2019 at 15:42
1 Answer
Reset to default 9You can use the following:
this.$nuxt.$data.layoutName
Which will return the name of the layout file used.