Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set the navigation bar and sidebar as public pages by vue

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces how to set up the navigation bar, sidebar for public pages related knowledge, detailed and easy to understand, simple and fast operation, with a certain reference value, I believe everyone read this vue how to set up the navigation bar, sidebar for public pages articles will have some harvest, let's take a look at it together.

First, the project structure is as follows:

想要让导航栏、侧边栏变为公共页面,则要在App.vue页面中加入。假设已经有了Header.vue和Left.vue,这里就不贴出来了,App.vue代码如下:

import header from './components/Header.vue';import left from './components/Left.vue'; export default{ components: { headerNav: header, left: left }}

此时运行会发现,所有的页面都被加上了这两个公共页面,而实际场景中,我们往往希望登录页是不需要导航栏和侧边栏的,那么就需要规避掉登录页。

这时,就可以采用keep-alive结合$route.meta来实现这个功能。keep-alive 是 Vue 内置的一个组件,可以使被包含的组件保留状态,或避免重新渲染。$route.meta则可以选择让需要的页面才展示。修改App.vue,如下:

import header from './components/Header.vue';import left from './components/Left.vue'; export default{ components: { headerNav: header, left: left }}

index.js代码如下:

import Vue from 'vue'import Router from 'vue-router'import HelloWorld from '@/components/HelloWorld' import Login from '@/views/Login'import index from '@/views/index'import versionList from '@/views/versionList' Vue.use(Router) export default new Router({ routes: [ { path: '/', name: 'login', component: Login, meta: { keepAlive: false } }, { path: '/index', name: 'index', component: index, meta: { keepAlive: true } }, { path: '/versionList', name: 'versionList', component: versionList, meta: { keepAlive: true } }, ]})

通过设置keepAlive的值就可以实现除了登录页不展示公共页面,在其他页面均展示的功能。

关于"vue如何设置导航栏、侧边栏为公共页面"这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对"vue如何设置导航栏、侧边栏为公共页面"知识都有一定的了解,大家如果还想学习更多知识,欢迎关注行业资讯频道。

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report