vue-router2.0二级路由的简单使用
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 跳转而无须重新加载页面。
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二级路由的简单使用的更多相关文章
- Vue学习(三)-Vue-router路由的简单使用
一.Vue-Router环境的安装: 如果使用vue-cli脚手架搭建,项目创建过程中会提示你自否选择使用vue-router,选择使用即可, 二.路由学习 1.路由的配置 vue-cli项目自 ...
- vue 2.0 路由切换以及组件缓存源代码重点难点分析
摘要 关于vue 2.0源代码分析,已经有不少文档分析功能代码段比如watcher,history,vnode等,但没有一个是分析重点难点的,没有一个是分析大命题的,比如执行router.push之后 ...
- Vue2.0实现路由
Vue2.0和1.0实现路由的方法有差别,现在我用Vue 2.0实现路由跳转,话不多说,直接上代码 HTML代码 <div class="tab"> <route ...
- vue二级路由跳转后外部引入js失效问题解决方案
vue路由可以通过children嵌套,于是可以形成二级路由等等... 案例如下: routes: [ { path: '/', name: 'dy', component: dy, children ...
- vue之二级路由
router-view : <router-view> 组件是一个 functional 组件,渲染路径匹配到的视图组件 一 样式 1 在一个vue组件,<template>& ...
- 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 2.0 的建议学习顺序
起步 1. 扎实的 JavaScript / HTML / CSS 基本功.这是前置条件. 2. 通读官方教程 (guide) 的基础篇.不要用任何构建工具,就只用最简单的 <script> ...
随机推荐
- bzoj1999 (洛谷1099) 树网的核——dfs
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1999 https://www.luogu.org/problemnew/show/P109 ...
- Python Flask Web 框架入门
Python Flask 目录 本文主要借鉴 letiantian 的文章 http://www.letiantian.me/learn-flask/ 一.简介 二.安装 三.初始化Flask 四.获 ...
- bzoj 1878: [SDOI2009]HH的项链【树状数组】
对于一个lr,每个颜色贡献的是在(1,r)区间里出现的最右位置,所以记录一个b数组表示当前点这个颜色上一个出现的位置 然后把询问离线,按r升序排序 每次把右端点右移,把这个点在树状数组上+1,并且在当 ...
- QQ自动登录Demo源码(附全套WindowsApi)
在开发过程中,偶尔会有自动化操作软件的需求,便想到用句柄实现自动化的功能,记录下知识点,以作备忘. 实现流程: 获取窗口句柄,根据定位获取input,调用windowsapi模拟鼠标点击, 输入 , ...
- php做APP接口开发,接口的安全性
1.当用户登录APP时,使用https协议调用后台相关接口,服务器端根据用户名和密码时生成一个access_key,并将access_key保存在session(或者保存在redis)中,将生成的ac ...
- linux rpm 安装
1.rpm 安装rpm -ivh package_name-i:install的意思-v:查看更详细的安装信息-h:以安装信息栏显示安装进度rpm -ivh package_name --test 2 ...
- js复制功能
// 复制功能 copyUrl() { var Url = document.getElementById('biao') Url.select() // 选择对象 document.execComm ...
- 287 Find the Duplicate Number 寻找重复数
一个长度为 n + 1 的整形数组,其中的数字都在 1 到 n 之间,包括 1 和 n ,可知至少有一个重复的数字存在.假设只有一个数字重复,找出这个重复的数字.注意: 不能更改数组内容(假设数 ...
- Windows Install Twisted 安装Twisted
1.下载twisted exe https://twistedmatrix.com/Releases/Twisted/15.4/ (注意最新版16.x没有适用于windows的exe,只能用旧版) 2 ...
- SQL传入时间获取到时间的周一和周日
declare @time datetime declare @timeMonday datetime set @time='2013-11-07' ) ,@time) select @timeMon ...