1、首先需要按照Vue router支持

 npm install vue-router
然后需要在项目中引入:
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

2、定义router的js文件

import Vue from 'vue'
import Router from 'vue-router'
import User from '../pages/user'
import Home from '../pages/public/home'
import Profile from '../pages/user/profile'
import Form from '../pages/form'
import Detail from '../pages/form/form'
import File from '../pages/form/file'
import Files from '../pages/file' Vue.use(Router) export default new Router({
routes: [
{ path: '/', component:Home,
children:[
{ path: '/user', component:Profile},
{ path: '/profile', component: User},
{ path: '/form', component: Form},
{ path: '/detail', component: Detail},
{ path: '/profiles', component: Files},
{ path: '/file', component: File}
]
},
       { path: '/login', component:Login},
{ path: '/404', component:Error}
   ] 
})

3、在main.js中引入router

import router from './router'

new Vue({
router,
render: h => h(App),
}).$mount('#app')

4、入口页面定义router-view

<div id="app">
<router-view></router-view>
</div>

5、在path指向为“/”的页面中,定义页面的布局,例如:上(头部)-中(左道航-右内容)-下(底部)。

<HeaderSection></HeaderSection>
<div>
<NavList class="nav"></NavList>
<router-view class="router"></router-view>
</div>
<FooterSection></FooterSection>

6、左侧导航,用elementUI实现,有一个NavMenu导航菜单,做导航功能。

在这里提一下引入elementUI:

(1)安装

 npm i element-ui -S

(2)使用

  在main.js中加入下面的代码:

  import ElementUI from 'element-ui';

  import 'element-ui/lib/theme-chalk/index.css';

  Vue.use(ElementUI);

导航栏的代码如下:

<el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#324157"
text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router>
<template v-for="item in items">
<template v-if="item.subs">
<el-submenu :index="item.index" :key="item.index">
<template slot="title">
<i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
</template>
<template v-for="subItem in item.subs">
<el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
<template slot="title">{{ subItem.title }}</template>
<el-menu-item v-for="(threeItem,i) in subItem.subs" :key="i" :index="threeItem.index">
{{ threeItem.title }}
</el-menu-item>
</el-submenu>
<el-menu-item v-else :index="subItem.index" :key="subItem.index">
{{ subItem.title }}
</el-menu-item>
</template>
</el-submenu>
</template>
<template v-else>
<el-menu-item :index="item.index" :key="item.index">
<i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
</el-menu-item>
</template>
</template>
</el-menu>

定义左侧导航的显示和图标等内容,index为唯一标识,打开的是path路径,对应router中的path,就可以打开写好的相应的页面。

           items: [
{
icon: 'el-icon-share',
index: 'user',
title: '系统首页'
},
{
icon: 'el-icon-time',
index: 'profile',
title: '基础表格'
},
{
icon: 'el-icon-bell',
index: '',
title: '表单相关',
subs: [
{
index: 'form',
title: '基本表单'
},
{
index: '3-2',
title: '三级菜单',
subs: [
{
index: 'detail',
title: '富文本编辑器'
},
{
index: 'file',
title: 'markdown编辑器'
},
]
},
{
index: 'profiles',
title: '文件上传'
}
]
},
]

7、如果涉及到登录页面和不需要路由的页面等,就需要在router的js文件中定义和“/”平级的其他path的页面,再判断进入页面是路由页面还是登录等页面。

vue路由--网站导航功能的更多相关文章

  1. Vue路由实现之通过URL中的hash(#号)来实现不同页面之间的切换(图表展示、案例分析、附源码详解)

    前言 本篇随笔主要写了Vue框架中路由的基本概念.路由对象属性.vue-router插件的基本使用效果展示.案例分析.原理图解.附源码地址获取. 作为自己对Vue路由进行页面跳转效果知识的总结与笔记. ...

  2. vue 路由里面的 hash 和 history

    对于 Vue 这类渐进式前端开发框架,为了构建 SPA(单页面应用),需要引入前端路由系统,这也就是 Vue-Router 存在的意义.前端路由的核心,就在于 —— 改变视图的同时不会向后端发出请求. ...

  3. Vue路由(vue-router)详细讲解指南

    中文文档:https://router.vuejs.org/zh/ Vue Router 是 Vue.js 官方的路由管理器.它和 Vue.js 的核心深度集成,让构建单页面应用变得易如反掌.路由实际 ...

  4. 「vue基础」一篇浅显易懂的 Vue 路由使用指南( Vue Router 上)

    大家好,今天的内容,我将和大家一起聊聊 Vue 路由相关的知识,如果你以前做过服务端相关的开发,那你一定会对程序的URL结构有所了解,我没记错的话也是路由映射的概念,需要进行配置. 其实前端这些框架的 ...

  5. Vue路由(vue-router)

    一.介绍 1.vue-router安装 官方文档:https://router.vuejs.org/zh/installation.html下载地址:https://unpkg.com/vue-rou ...

  6. Vue路由vue-router

    前面的话 在Web开发中,路由是指根据URL分配到对应的处理程序.对于大多数单页面应用,都推荐使用官方支持的vue-router.Vue-router通过管理URL,实现URL和组件的对应,以及通过U ...

  7. 攻克vue路由

    先下手 路由是个好功能,但是每次都感觉没法开始下手,愣愣的看半天官方文档,所以做个快速开始教程. 首先先搭好HTML文件结构: <!--link和view在一个父元素下--> <di ...

  8. Vue路由学习心得

    GoodBoy and GoodGirl~进来了就看完点个赞再离开,写了这么多也不容易的~ 一.介绍  1.概念:路由其实就是指向的意思,当我们点击home按钮时,页面中就要显示home的内容,点击l ...

  9. VUE路由新页面打开的方法总结

    平常做单页面的场景比较多,所以大部分的业务是在同一个页面进行跳转.要通过VUE路由使用新页面打开且传递参数,可以采用以下两个方法: 1.router-link的target <router-li ...

随机推荐

  1. 使用shell快速建立上万个文件夹

    #!/bin/bash#!This is a shell script to finish the folders tasks.rm -rf /home/cpay/zyc/filemkdir /hom ...

  2. maven打包如何跳过测试

    Maven打包如何跳过测试?正常来说,不应该这样做,因为测试可以避免很多麻烦排除一些不必要的错误,前提是测试足够规范,这里主要指junit测试,如果junit测试有问题的话,将会直接影响到mvn in ...

  3. Linux内核入门到放弃-页面回收和页交换-《深入Linux内核架构》笔记

    概述 可换出页 只有少量几种页可以换出到交换区,对其他页来说,换出到块设备上与之对应的后备存储器即可,如下所述. 类别为 MAP_ANONYMOUS 的页,没有关联到文件,例如,这可能是进程的栈或是使 ...

  4. Vue(五)Vue规范

    代码规范很重要 1.组件名应该始终是多个单词的,根组件 App 除外. 2.组件的 data 必须是一个函数. // In a .vue file export default { data () { ...

  5. Web后台快速开发框架(.NET Core)

    Web后台快速开发框架(.NET Core) Coldairarrow 目录 目录 第1章    目录    1 第2章    简介    3 第3章    基础准备    4 3.1    开发环境 ...

  6. python中使用redis发布订阅者模型

    redis发布订阅者模型: Redis提供了发布订阅功能,可以用于消息的传输,Redis的发布订阅机制包括三个部分,发布者,订阅者和Channel.发布者和订阅者都是Redis客户端,Channel则 ...

  7. 美化ubuntu18.04,并安装搜狗输入法

    目录 美化Ubuntu 下载主题和图标文件 下载GNOME3 美化过程 安装输入法 下载并安装搜狗输入法 安装fcitx框架 安装过程 美化Ubuntu 下载主题和图标文件 下载地址:https:// ...

  8. const命令

    一.基本用法 声明一个只读的常量,这个值不会变. const声明常量与let一样,不可重复声明. 二.本质(我困惑的地方) const实际上保证的并不是变量的值不可以改动,而是变量指向的内存地址不可改 ...

  9. vs code 的便捷使用

    鼠标滚动 改变字体大小 打开编辑器设置,搜索 editor.mouseWheelZoom  或者文本设置 自动保存 打开设置 搜索  autosave

  10. mobilebone与weiui_example.css 使用问题

    weiui_example.css 原page样式属性opacity设置为0 ... 由于我采取的是使用mobilebone,没按照weui官网的来搞这种效果,所以这里会有冲突,设置为默认即可,即op ...