1、app.vue中

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

2、router中index.js(路由的路径配置)

import Vue from 'vue'
import Router from 'vue-router'
import Hello from '@/components/Hello'
import Login from '@/components/Login'
import index from '@/components/index'
import Header from '@/components/Header/Header'
import Product from '@/components/Product/Product' Vue.use(Router) export default new Router({

  //vue-router 默认 hash 模式 —— 使用 URL 的 hash 来模拟一个完整的 URL,于是当 URL 改变时,页面不会重新加载。

//如果不想要很丑的 hash,我们可以用路由的 history 模式,这种模式充分利用 history.pushState API 来完成 URL 跳转而无须重新加载页面。

   mode: 'history',//可以是去掉#号
  routes: [
{
path: '/',
name: 'Login',
component: Login
},
{
path: '/index',
name: 'index',
component: index,
children: [ //这里就是二级路由的配置
{
path: '/hello',
name: 'Hello',
component: Hello
},
{
path: '/header',
name: 'Header',
component: Header
},
{
path: '/product',
name: 'Product',
component: Product
}
]
}
]
})

3、下面是我们的index.vue中的代码

<template>
<div class="aaa">
<div class="list-group">
<router-link to="/hello">Go to hello</router-link>
<router-link to="/header">Go to header</router-link>
<router-link to="/product">Go to product</router-link>
<input type="text" v-model="username">
<button v-click="text"></button>
<router-view></router-view>
</div>
</div>
</template>

4、最后就是新建hello、header、product这几个组件来验证我们的效果,这里就不做演示了,因为我自己已经测试过了,没有问题

vue-router2.0二级路由的简单使用的更多相关文章

  1. Vue学习(三)-Vue-router路由的简单使用

    一.Vue-Router环境的安装: 如果使用vue-cli脚手架搭建,项目创建过程中会提示你自否选择使用vue-router,选择使用即可, 二.路由学习 1.路由的配置    vue-cli项目自 ...

  2. vue 2.0 路由切换以及组件缓存源代码重点难点分析

    摘要 关于vue 2.0源代码分析,已经有不少文档分析功能代码段比如watcher,history,vnode等,但没有一个是分析重点难点的,没有一个是分析大命题的,比如执行router.push之后 ...

  3. Vue2.0实现路由

    Vue2.0和1.0实现路由的方法有差别,现在我用Vue 2.0实现路由跳转,话不多说,直接上代码 HTML代码 <div class="tab"> <route ...

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

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

  5. vue之二级路由

    router-view : <router-view> 组件是一个 functional 组件,渲染路径匹配到的视图组件 一 样式 1 在一个vue组件,<template>& ...

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

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

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

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

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

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

  9. 新手入门指导:Vue 2.0 的建议学习顺序

    起步 1. 扎实的 JavaScript / HTML / CSS 基本功.这是前置条件. 2. 通读官方教程 (guide) 的基础篇.不要用任何构建工具,就只用最简单的 <script> ...

随机推荐

  1. [POI2012]FES-Festival

    https://www.zybuluo.com/ysner/note/1252538 题面 有一个数列\(\{a\}\).现给定多组限制,限制分成\(2\)类,第一类是\(a_x+1=a_y\),有\ ...

  2. python之Beautiflusoup操作

    from bs4 import BeautifulSoupimport requestsimport os ######对风景进行爬出操作r = requests.get("http://6 ...

  3. C#自动内存分配

    一.在程序运行时由CLR管理内存分配(Memory Allocation),程序启动时,操作系统会为每一个线程申请一个独立的栈内存,用于存储方法的局部变量.参数和返回值等:CLR会为进程申请一个连续的 ...

  4. Winform执行CMD命令

    1.首先分享CmdHelper类: using System; using System.Collections.Generic; using System.Text; using System.Di ...

  5. 双摆模拟 python(转)

    双摆 是 混沌理论 中的一个常见示例,这里通过 python 的作图工具包Matplotlib 来模拟双摆的运动过程: 注意:在 vs2017 中可以正确运行程序,在 cmd 环境下有时报错 &quo ...

  6. 385 Mini Parser 迷你解析器

    Given a nested list of integers represented as a string, implement a parser to deserialize it.Each e ...

  7. 306 Additive Number 加法数

    Additive number is a string whose digits can form additive sequence.A valid additive sequence should ...

  8. 网站开发综合技术 第一部分HTML 1.3.2表单

    <form id="" name="" method="post/get" action="负责处理的服务端"&g ...

  9. IIS配置负载均衡

    一.下载Nginx安装包 二.修改nginx.conf文件信息 如图: 三.重新加载Nginx (nginx -s reload) 启动Nginx: start nginx 停止Nginx:nginx ...

  10. CF842C Ilya And The Tree

    思路: 1. 如果根节点是0,那么可以通过一次dfs计算出所有节点的最大值. 2. 如果根节点不是0,那么其余各点的最大值一定是根节点的一个因子.首先计算出根节点的所有因子.在dfs到一个深度为d的节 ...