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: '3', 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路由--网站导航功能详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。