Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

nuxt.js - How to better extend layout with conditional component in Nuxt?

Currently, I am having 3 layouts:

  1. has header and sidebar
  2. has header no sidebar
  3. has no header nor sidebar

What is the way to extend the layout with options whether to turn on or off the sidebar and header? These are 3 possibilities but I'm sure there should be better way

  1. Use 1 layout with vuex state. Set the showHeader and showSidebar beforeMount
  2. Use 1 layout with $route condition to show header and sidebar
  3. Use 3 layouts

Does anyone know any better way?

question from:https://stackoverflow.com/questions/65882458/how-to-better-extend-layout-with-conditional-component-in-nuxt

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If displaying header statically, i would prefer to separate 2 layout.

  1. has header
  2. has no header

And control the sidebar open/close state from vuex by user prefer.

If header preference is dynamically,

one default layout and control header and sidebar open/close state from vuex


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...