vue路由--网站导航功能
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路由--网站导航功能的更多相关文章
- Vue路由实现之通过URL中的hash(#号)来实现不同页面之间的切换(图表展示、案例分析、附源码详解)
前言 本篇随笔主要写了Vue框架中路由的基本概念.路由对象属性.vue-router插件的基本使用效果展示.案例分析.原理图解.附源码地址获取. 作为自己对Vue路由进行页面跳转效果知识的总结与笔记. ...
- vue 路由里面的 hash 和 history
对于 Vue 这类渐进式前端开发框架,为了构建 SPA(单页面应用),需要引入前端路由系统,这也就是 Vue-Router 存在的意义.前端路由的核心,就在于 —— 改变视图的同时不会向后端发出请求. ...
- Vue路由(vue-router)详细讲解指南
中文文档:https://router.vuejs.org/zh/ Vue Router 是 Vue.js 官方的路由管理器.它和 Vue.js 的核心深度集成,让构建单页面应用变得易如反掌.路由实际 ...
- 「vue基础」一篇浅显易懂的 Vue 路由使用指南( Vue Router 上)
大家好,今天的内容,我将和大家一起聊聊 Vue 路由相关的知识,如果你以前做过服务端相关的开发,那你一定会对程序的URL结构有所了解,我没记错的话也是路由映射的概念,需要进行配置. 其实前端这些框架的 ...
- Vue路由(vue-router)
一.介绍 1.vue-router安装 官方文档:https://router.vuejs.org/zh/installation.html下载地址:https://unpkg.com/vue-rou ...
- Vue路由vue-router
前面的话 在Web开发中,路由是指根据URL分配到对应的处理程序.对于大多数单页面应用,都推荐使用官方支持的vue-router.Vue-router通过管理URL,实现URL和组件的对应,以及通过U ...
- 攻克vue路由
先下手 路由是个好功能,但是每次都感觉没法开始下手,愣愣的看半天官方文档,所以做个快速开始教程. 首先先搭好HTML文件结构: <!--link和view在一个父元素下--> <di ...
- Vue路由学习心得
GoodBoy and GoodGirl~进来了就看完点个赞再离开,写了这么多也不容易的~ 一.介绍 1.概念:路由其实就是指向的意思,当我们点击home按钮时,页面中就要显示home的内容,点击l ...
- VUE路由新页面打开的方法总结
平常做单页面的场景比较多,所以大部分的业务是在同一个页面进行跳转.要通过VUE路由使用新页面打开且传递参数,可以采用以下两个方法: 1.router-link的target <router-li ...
随机推荐
- Deep Reinforcement Learning for Dialogue Generation 论文阅读
本文来自李纪为博士的论文 Deep Reinforcement Learning for Dialogue Generation. 1,概述 当前在闲聊机器人中的主要技术框架都是seq2seq模型.但 ...
- Linux新手随手笔记1.6
RAID磁盘冗余阵列 1.I/O 速度 2.数据安全性 RAID 0 负载均衡.速度乘以二,但是数据安全性不行,任何一块盘损坏数据都会丢失. RAID 1 安全性性提升2倍,任何一个损坏另一个都有 ...
- ASP.NET Core 2.2 : 十六.扒一扒新的Endpoint路由方案
ASP.NET Core 从2.2版本开始,采用了一个新的名为Endpoint的路由方案,与原来的方案在使用上差别不大,但从内部运行方式上来说,差别还是很大的.上一篇详细介绍了原版路由方案的运行机制, ...
- linux-----docker
docker简介 Docker时Docker.Lnc公司开源的一个基于LXC技术之上搭建的Container容器引擎,源代码托管在Github上,基于Go语言并遵从Apache2.0协议开源. Doc ...
- 让自己的开源项目支持CocoaPods
测试的时候找个自己封装的方法或UI控件就可以了 这里用我刚封装的Redirect重定向的请求体为例 1, 在github上创建一个Redirect,重要:记得选择开源协议 (MIT)(如果木有GitH ...
- java事件监听机制
1.简单的事件监听 package demo2; /* * java事件监听机制 */ import java.awt.*; import javax.swing.*; import java.awt ...
- jsonp原理详解
1.一个众所周知的问题,Ajax直接请求普通文件存在跨域无权限访问的问题,甭管你是静态页面.动态网页.web服务.WCF,只要是跨域请求,一律不准. 2.不过我们又发现,Web页面上调用js文件时则不 ...
- [蓝桥杯]2014蓝桥省赛B组题目及详解
/*——————————————————————————————————————————————————————————— [结果填空题]T1 题目:啤酒和饮料 啤酒每罐2.3元,饮料每罐1.9元.小 ...
- PHP细节,PHP手册中常见的一句话:该函数是二进制安全的
以下内容转自 http://wuxinjie.github.io/php-02/ 在看PHP手册的时候,经常看到一句话”该函数是二进制安全的”. 二进制安全是什么呢? 他是如何实现的? 二进制安全是什 ...
- 《转载》最新鲜最详细的Android SDK下载安装及配置教程
Android开发环境搭建可以分: 第一步.安装JDK: 第二步.安装Eclipse: 第三步.下载并安装AndroidSDK: 下面详细介绍. 第一步.安装JDK Android开发工具要求必须 ...