最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to tell what layout is being used within a Nuxt.js component? - Stack Overflow

programmeradmin3浏览0评论

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 in default.vue when you render footer.vue give it a prop type called 'default'. Same with secondary.vue. And then in footer.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
Add a ment  | 

1 Answer 1

Reset to default 9

You can use the following:

this.$nuxt.$data.layoutName

Which will return the name of the layout file used.

发布评论

评论列表(0)

  1. 暂无评论