search

Home  >  Q&A  >  body text

javascript - Vue-based spa website, the head and tail of some pages are not fixed

Use vue to make a spa website, but some pages do not require headers and tails, or the headers are slightly different. For example, if you click to log in, you do not need a header and navigation bar. What to do at this time? One method is to make the head and tail components into components, and then import these two components into the required pages, but it feels like the amount of code is too much. Is there any other way besides this?

PHPzPHPz2780 days ago726

reply all(6)I'll reply

  • 世界只因有你

    世界只因有你2017-05-19 10:26:50

    You can refer to the named view upstairs.
    I will send you a router configuration, you will understand it at a glance

    routes: [
        {
          path: '/login',
          name: 'login',
          meta: {auth: false, title: '登录'},
          component: Login
        },
        {
          path: '/',
          meta: {title: '首页', active: 1},
          component: resolve => require(['../pages/main'], resolve),
          children: [
            erp,
            crm,
            ...
    }]

    main.vue

    <template>
      <el-row class="container">
        <el-col :span="24" class="header">
          <router-view name="top"></router-view>
        </el-col>
        <el-col :span="24" class="main">
          <aside>
            <router-view name="left"></router-view>
          </aside>
          <section class="content-container">
            <transition name="fade">
              <router-view keep-alive></router-view>
            </transition>
          </section>
        </el-col>
      </el-row>
    </template>

    reply
    0
  • 怪我咯

    怪我咯2017-05-19 10:26:50

    Write everything in, show it when needed, hide it when not needed?
    But isn’t your own method pretty good? The beginning and end are common, and you can load them based on the routing

    reply
    0
  • 高洛峰

    高洛峰2017-05-19 10:26:50

    Is it possible to add a judgment condition and whether to display the head and tail according to the condition? v-if else

    reply
    0
  • 怪我咯

    怪我咯2017-05-19 10:26:50

    Write multi-level routing.

    reply
    0
  • 天蓬老师

    天蓬老师2017-05-19 10:26:50

    You can consider the named view of vue-route. The specific needs will depend on the business

    reply
    0
  • 某草草

    某草草2017-05-19 10:26:50

    Follow me if you encounter this problem

    reply
    0
  • Cancelreply