vue之二级路由
router-view :
<router-view> 组件是一个 functional 组件,渲染路径匹配到的视图组件
一 样式
1 在一个vue组件,<template></template>中,在加入<router-view></router-view>
<template>
<div>
.......
<router-view></router-view>
</div>
</template>
2 在路由中 router/index.js 中,
{
path:'/xx',
name:'',
component:xx,
children:[
path:' oo ' 注意:没有 /
name:' oo', 这个是用于反向查找, 组件中 <router-link :to="{name:'oo'}">oo</router-link>, name对应的就是 路由中的name。注意 是 :to = " { name:' oo'}"
component:oo, 从前到后找到这个组件,先一级组件,在二级组件
]
}
3 每一个 二级路由都对应独自的 vue组件。
通过反向查找,先加载一级路由"xx",在加载二级路由"oo"。
二 代码示例
App.vue
<template>
<div id="app">
<Header></Header>
<router-view></router-view>
<Footer></Footer>
</div>
</template> <script>
import Header from './components/Header.vue'
import Footer from './components/Footer.vue'
export default {
name: 'App',
components:{
Header,
Footer,
}
}
</script> <style> </style>
路由
Vue.use(Router)
export default new Router({
mode:'history',
routes: [
{
path: '/',
name: 'index',
component: Index,
},
{
path: '/index',
name: 'index',
component: Index,
},
{
path: '/course',
name: 'course',
component: Course,
},
{
path: '/news',
name: 'news',
component: News,
},
{
path: '/help',
name: 'help',
component: Help,
children:[
{
path: 'aboutus',
name: 'aboutus',
component: Aboutus,
},
{
path: 'feedback',
name: 'feedback',
component: Feedback,
},
{
path: 'usernote',
name: 'usernote',
component: Usernote,
},
]
},
]
})
项目结构

help.vue
<template>
<div>
<p>{{msg}}</p>
<router-view></router-view>
</div>
</template> <script>
export default{
name:'help',
data(){
return{
msg:'这是帮助信息',
}
}
}
</script> <style> </style>
三 有什么用
当指向不同的url时,部分页面是相同的,部分页面才需要改变,这个时候,用二级路由比较合适。 不变的放在一级,需要变化的放在二级。
vue之二级路由的更多相关文章
- vue二级路由跳转后外部引入js失效问题解决方案
vue路由可以通过children嵌套,于是可以形成二级路由等等... 案例如下: routes: [ { path: '/', name: 'dy', component: dy, children ...
- Vue 中的Vue Router一级路由,二级路由,三级路由以及跳转
今天编写了一下Vue中的路由 先用命令行新建一个空的项目,并且我知道要用路由,就下载了路由的相关依赖 vue init webpack demo5 完毕之后进入所在的项目 cd demo5 之后用vs ...
- 每天一点点之vue框架开发 - vue-router路由进阶(路由别名、跳转、默认路由、二级路由、路由守卫)
路由别名 在main.js中的路由中添加name来创建别名 const routes = [ {path:'/footer',name:footerLink,component:Footer} ] ...
- vue 路由知识点(一级路由与二级路由嵌套)
本人小白一个,如果问题,麻烦大神指点, 一级路由: path:'/' 默认为显示; 二级路由: path: '',默认显示为index组件,因为二级路有没有写index组件,所以使用redirect: ...
- vue-router 二级路由
/** * Created by 我 on 2017/12/4. */ import Vue from 'vue' //import导入 Vue(自己起的名) from 从 vue import Vu ...
- nuxt二级路由
耗费了大半天的时间,终于把页面的二级路由配置好了 先看我的目录 如果没有登陆页,根本就不用考虑嵌套路由的问题,主要的menu跳转和<nuxt />可以直接写到layouts/default ...
- vue-router2.0二级路由的简单使用
1.app.vue中 <template> <div id="app"> <router-view></router-view> & ...
- 链接进入react二级路由,引发的子组件二次挂载
这个问题很怪,我两个二级路由从链接进入的时候,会挂载两次子组件. 从链接进入,是因为新页面在新标签页打开的. 有子组件是因为公共组件提取 同样的操作,有一些简单的二级路由页面,就不会挂载两次. 讲道理 ...
- Vue 实现动态路由及登录&404页面跳转控制&页面刷新空白解决方案
Vue实现动态路由及登录&404页面跳转控制&页面刷新空白解决方案 by:授客 QQ:1033553122 开发环境 Win 10 Vue 2.9.6 node-v ...
随机推荐
- Slacklining 2017/2/6
原文 Get ready for a different kind of challenge What happens when mountain climbers take a day off?Ap ...
- [习题]输入自己的生日(年/月/日)#2 -- 日历(Calendar)控件的时光跳跃,一次跳回五年、十年前?--TodaysDate属性、VisibleDate属性
原文出處 http://www.dotblogs.com.tw/mis2000lab/archive/2013/06/10/calendar_visibledate_birthday_dropdow ...
- More helpful Cocos2d and Gaming macros
More helpful Cocos2d and Gaming macros Here are w few macros that i wrote to make the code more read ...
- 解决Errno::ENOENT: No Such File or Directory - Jekyll ~ Octopress and El Capitan
参考http://schalkneethling.github.io/blog/2015/10/16/errno-enoent-no-such-file-or-directory-jekyll-oct ...
- 51nod 1412 AVL数的种类(DP
题意给了n个节点 问AVL树的种类 卧槽 真的好傻 又忘记这种题可以打表了 就算n^3 也可以接受的 树的深度不大 那么转移方程很明显了 dp[i][j] 代表的是节点为n深度为j的树的种类 k ...
- C02 信息存储与运算
目录 计算机内存 常量和变量 数据类型 运算符 计算机内存管理 计算机内存 信息存储概述 使用程序进行开发时,需要存储各种信息,这时候就需要用到变量.由于信息类型不同,变量的类型也因此不尽相同. 同时 ...
- 7.逻辑运算 and or not
1)优先级 ()> not > and > o r and:真真为真,真假为假 ,假假为假 or:真真为真,真假为真,假假为假 print(2 > 1 and 1 < ...
- Spring框架 aop中的操作术语
Joinpoint 连接点 Pointcut 切入点 Advice 通知/增强 举例: 后置通知,不抛出异常则执行此通知,抛异常则不执行 最终通知,抛不抛异常都通知 其他通知都是环绕通知的衍生 ...
- Xcode及Mac快捷键
1. 文件 CMD + N: 新文件CMD + SHIFT + N: 新项目CMD + O: 打开CMD + S: 保存CMD + SHIFT + S: 另存为CMD + W: 关闭窗口CMD + S ...
- vue 封装分页组件
分页 一般都是调接口, 接口为这种格式 {code: 0, msg: "success",…} code:0 data:{ content:[{content: "11& ...