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之二级路由的更多相关文章

  1. vue二级路由跳转后外部引入js失效问题解决方案

    vue路由可以通过children嵌套,于是可以形成二级路由等等... 案例如下: routes: [ { path: '/', name: 'dy', component: dy, children ...

  2. Vue 中的Vue Router一级路由,二级路由,三级路由以及跳转

    今天编写了一下Vue中的路由 先用命令行新建一个空的项目,并且我知道要用路由,就下载了路由的相关依赖 vue init webpack demo5 完毕之后进入所在的项目 cd demo5 之后用vs ...

  3. 每天一点点之vue框架开发 - vue-router路由进阶(路由别名、跳转、默认路由、二级路由、路由守卫)

    路由别名   在main.js中的路由中添加name来创建别名 const routes = [ {path:'/footer',name:footerLink,component:Footer} ] ...

  4. vue 路由知识点(一级路由与二级路由嵌套)

    本人小白一个,如果问题,麻烦大神指点, 一级路由: path:'/' 默认为显示; 二级路由: path: '',默认显示为index组件,因为二级路有没有写index组件,所以使用redirect: ...

  5. vue-router 二级路由

    /** * Created by 我 on 2017/12/4. */ import Vue from 'vue' //import导入 Vue(自己起的名) from 从 vue import Vu ...

  6. nuxt二级路由

    耗费了大半天的时间,终于把页面的二级路由配置好了 先看我的目录 如果没有登陆页,根本就不用考虑嵌套路由的问题,主要的menu跳转和<nuxt />可以直接写到layouts/default ...

  7. vue-router2.0二级路由的简单使用

    1.app.vue中 <template> <div id="app"> <router-view></router-view> & ...

  8. 链接进入react二级路由,引发的子组件二次挂载

    这个问题很怪,我两个二级路由从链接进入的时候,会挂载两次子组件. 从链接进入,是因为新页面在新标签页打开的. 有子组件是因为公共组件提取 同样的操作,有一些简单的二级路由页面,就不会挂载两次. 讲道理 ...

  9. Vue 实现动态路由及登录&404页面跳转控制&页面刷新空白解决方案

    Vue实现动态路由及登录&404页面跳转控制&页面刷新空白解决方案   by:授客 QQ:1033553122   开发环境   Win 10   Vue 2.9.6   node-v ...

随机推荐

  1. 怎样配置JDK开发环境

    (1)我们需要配置三个环境变量,分别是JAVA_HOME,CLASSPATH,Path (2)变量名输入:JAVA_HOME,变量值输入:D:\Java\jdk1.8.0_05点击确定. 需要特别注意 ...

  2. 新版raspbian系统的固定IP配置和启用root账户的ssh登录功能的方法

    1. 2016新版raspbian系统的固定IP配置: 自2016年2月份新版raspbian系统发布以后,树莓派的固定IP配置方法就与之前不一样了. 之前在raspbian系统中编辑/etc/net ...

  3. SNP|RELP|genetic polymorphism|

    5.3个体基因组呈现广泛变化 遗传多态性:一个基因座上存在多个等位基因(因为野生型不止一种基因)的现象,但是只有这多种等位基因满足:1.多个基因稳定存在2.基因在种群中数目大于1%时,认为该基因座多态 ...

  4. 设置tableview的滚动范围--iOS开发系列---项目中成长的知识三

    设置tableview的滚动范围 有时候tableview的footerview上的内容需要向上拖动界面一定距离才能够看见, 项目中因为我需要在footerviw上添加一个按钮,而这个按钮又因为这个原 ...

  5. Bzoj 1055: [HAOI2008]玩具取名 (区间DP)

    Bzoj 1055: [HAOI2008]玩具取名 (区间DP) 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1055 区间动态规划和可 ...

  6. virtualenvwrapper.sh报错: There was a problem running the initialization hooks.解决

    由于在ubuntu环境下,将python做与python3.6做了软链接(ln -s python python3.6),并且pip也被我做了软链接,所以导致用pip安装virtualenvwrapp ...

  7. mysql5.7.22-log 修改远程访问

    正常的设置账号远程访问依然访问不了的情况,可以看一下服务器 my.cnf配置文件下 [client] #password = your_password 把上面的#去掉就行了.

  8. Pandas中loc,iloc与直接切片的区别

    最近使用pandas,一直搞不清楚其中几种切片方法的区别,今天专门看了一下. 0. 把Series的行index或Dataframe的列名直接当做属性来索引. 如: s.index_name df.c ...

  9. LeetCode 637. Average of Levels in Binary Tree(层序遍历)

    Given a non-empty binary tree, return the average value of the nodes on each level in the form of an ...

  10. redux学习总结

    redux学习总结 *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !imp ...