<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="" name="Keywords">
<meta content="" name="description"/>
<title></title>
<link rel="icon" href="">
<style>
.router-link-active{
color: #ee2ad6;
}
</style>
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> </head>
<body>
<div id="app">
<!-- router-link 标签上的tag 是修改展示的标签元素的 不写的话默认 a标签
active-class 是控制当前选中状态的类名的额,后边跟的值就是选中状态下的类名
不写这个属性,默认选中的类名就是 router-link-active
exact-active-class 精确(会把传的一些参数认成不同路径)匹配 路由
不写这个属性,默认选中的类名就是 router-link-exact-active
-->
<!-- <router-link to="/home" tag="button" active-class="current">首页</router-link>
<router-link to="/list" tag="button" exact-active-class="exactClass">列表页</router-link>-->
<!--query 这个单词是vue-router 规定的;
后边跟的是个对象,router会把对象中的每一项拼接到路由后边-->
<router-link :to="{path:'/home',query:{name:12,age:13}}">首页</router-link>
<!--params 这个单词也是vue-router规定的,它是对象中的参数当做路拼到之前的路径上
这个地方不能再用path跳转 必须用name跳转-->
<router-link :to="{name:'q',params:{name:12}}"> 列表页</router-link>
<router-view></router-view>
</div> </body>
</html>
<script src="node/node_modules/vue/dist/vue.js"></script>
<script src="node/node_modules/vue-router/dist/vue-router.js"></script>
<script> let home = {
template:"<h2>首页</h2>",
mounted(){
console.log(this.$route.query); //通过$route 可以获取路径上的参数
console.log(this);
}
};
let list = {
template:"<h2>列表页</h2>",
mounted(){
console.log(this.$route.params);
console.log(this);
}
}; const routes=[
{
path:'/home',
component:home
},
{
path:'/list/:name', //若想要路径传参,则需要在路径参数对应的位置写成:变量的形式
//这个变量会对应上 在行内设置的params对象中的属性名对应的属性值
name:'q', //若想用路径传参,则必须用name去指定跳转路径
component:list
}
];
const router=new VueRouter({
routes,
// mode:'history'
linkActiveClass:'current2' , //这个是给全局的选中状态下的 router-link修改类名
linkExactActiveClass:'activeClass'
});
let vm = new Vue({
el: '#app', data: {},
router,
created(){ },
directives: {},
methods: {},
computed: {},
watch: {},
filters: {}
})
</script>

router-link的使用方法的更多相关文章

  1. navigate是Router类的一个方法,主要用来跳转路由。

    navigate是Router类的一个方法,主要用来跳转路由. 1 2 3 4 5 6 7 8 9 interface NavigationExtras {  relativeTo : Activat ...

  2. [Redux] Navigating with React Router <Link>

    We will learn how to change the address bar using a component from React Router. In Root.js: We need ...

  3. Vue router link

    html: <router-link to="test">Go to Foo</router-link> <router-link to=" ...

  4. [React] React Router: Router, Route, and Link

    In this lesson we'll take our first look at the most common components available to us in react-rout ...

  5. angular2 学习笔记 ( Router 路由 )

    参考 : https://angular.cn/docs/ts/latest/guide/router.html#!#can-activate-guard https://angular.cn/doc ...

  6. React Router教程

    React Router教程 React项目的可用的路由库是React-Router,当然这也是官方支持的.它也分为: react-router 核心组件 react-router-dom 应用于浏览 ...

  7. React Router 用法

    React Router 用法 一.DEMO import React from "react"; import { HashRouter as Router, Route, Li ...

  8. React Router学习

    React Router教程 本教程引用马伦老师的的教程 React项目的可用的路由库是React-Router,当然这也是官方支持的.它也分为: react-router 核心组件 react-ro ...

  9. react-router5.x 的配置及其页面跳转方法和js跳转方法

    https://blog.csdn.net/sinat_37255207/article/details/90745207 上次用react-router 的时候  还是3.x 很久不用 已经到rea ...

  10. vue router应用及总结

    编写一个小的demo,对router基础的应用学习和理解. 效果图示: 说明: 点击About在右边显示相关信息. 说明: 点击Home,在下边显示相关信息,且Home下有两个路由链接,分别对应各自的 ...

随机推荐

  1. bootstrap复选框和单选按钮

    复选框和单选按钮标签包含在<Label>标签中<div class="checkbox"> <label><input type=&quo ...

  2. Scanner类nextLine()和next()的区别和使用方法

    next()一定要读取到有效字符后才可以结束输入,对输入有效字符之前遇到的空格键.Tab键或Enter键等结束符,next()方法会自动将其去掉,只有在输入有效字符之后,next()方法才将其后输入的 ...

  3. 网易云MongoDB分片集群(Sharding)服务已上线

    此文已由作者温正湖授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. MongoDB sharding cluster(分片集群)是MongoDB提供的数据在线水平扩展方案,包括 ...

  4. 网站SEO优化如何让百度搜索引擎绝的你的网站更有抓取和收录价值呢?_孙森SEO

    今天孙森SEO为大家唠唠网站到底该如何优化才会让百度搜索引擎绝的你的网站更有抓取和收录价值呢? 第一方面:网站创造高品质的内容,可以为用户提供独特的价值. 1.百度作为搜索引擎,网站内容必须满足 搜索 ...

  5. 【Aizu - 0005 】GCD and LCM

    GCD and LCM Descriptions: Write a program which computes the greatest common divisor (GCD) and the l ...

  6. C# 大文件上传

    IHttpModule 分块上传大文件 IHttpModule 分块上传大文件 来源:http://www.cnblogs.com/HeroBeast/archive/2008/03/18/10848 ...

  7. spring源代码下载并导入eclipse技巧

    环境:mac 安装brew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install ...

  8. elasticsearch全文搜索

    1.创建索引 PUT 192.168.100.102:9200/news 2.创建mapping POST 192.168.100.102:9200/news/new/_mapping { " ...

  9. 打开CAD时出现“acvmtools.arx ARX命令中发生异常

    打开CAD时出现“acvmtools.arx ARX命令中发生异常     解决办法1: 试试进入CAD安装的目录,删掉它acvmtools.arx,重新打开cad.(注:acvmtools.arx一 ...

  10. python网络爬虫之三re正则表达式模块

    """ re正则表达式,正则表达式是对字符串操作的一种逻辑公式,就是用事先定义好的 一些特定字符,及这些特定字符的组合,组成一个"规则字符串",然后用 ...