admin管理员组文章数量:1387462
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.
本文标签: javascriptHow to tell what layout is being used within a Nuxtjs componentStack Overflow
版权声明:本文标题:javascript - How to tell what layout is being used within a Nuxt.js component? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744563708a2612919.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论